fidl_fuchsia_hardware_i2c/
fidl_fuchsia_hardware_i2c.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_hardware_i2c__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18    type Proxy = DeviceProxy;
19    type RequestStream = DeviceRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DeviceSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.hardware.i2c.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26pub type DeviceTransferResult = Result<Vec<Vec<u8>>, i32>;
27pub type DeviceGetNameResult = Result<String, i32>;
28
29pub trait DeviceProxyInterface: Send + Sync {
30    type TransferResponseFut: std::future::Future<Output = Result<DeviceTransferResult, fidl::Error>>
31        + Send;
32    fn r#transfer(&self, transactions: &[Transaction]) -> Self::TransferResponseFut;
33    type GetNameResponseFut: std::future::Future<Output = Result<DeviceGetNameResult, fidl::Error>>
34        + Send;
35    fn r#get_name(&self) -> Self::GetNameResponseFut;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct DeviceSynchronousProxy {
40    client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
45    type Proxy = DeviceProxy;
46    type Protocol = DeviceMarker;
47
48    fn from_channel(inner: fidl::Channel) -> Self {
49        Self::new(inner)
50    }
51
52    fn into_channel(self) -> fidl::Channel {
53        self.client.into_channel()
54    }
55
56    fn as_channel(&self) -> &fidl::Channel {
57        self.client.as_channel()
58    }
59}
60
61#[cfg(target_os = "fuchsia")]
62impl DeviceSynchronousProxy {
63    pub fn new(channel: fidl::Channel) -> Self {
64        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
65        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
66    }
67
68    pub fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    /// Waits until an event arrives and returns it. It is safe for other
73    /// threads to make concurrent requests while waiting for an event.
74    pub fn wait_for_event(
75        &self,
76        deadline: zx::MonotonicInstant,
77    ) -> Result<DeviceEvent, fidl::Error> {
78        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
79    }
80
81    /// Issue one or more transactions to a particular I2C device.
82    ///
83    /// Each `Transaction` is performed in the order in which it appears in `transactions`. Data for
84    /// read transfers (if there are any) is returned through `read_data`, which has one entry for
85    /// each read transfer in `transactions`. Transaction processing continues until all transfers
86    /// have been completed, an error occurs, or the target issues a NACK in response to a write
87    /// transfer.
88    ///
89    /// The possible error values are:
90    ///   ZX_ERR_INVALID_ARGS: `transactions` has zero elements, `data_transfer` was not specified
91    ///     for a `Transaction`, or there was a zero-length `DataTransfer`.
92    ///   ZX_ERR_OUT_OF_RANGE: A `DataTransfer` was too large to be handled by this I2C controller.
93    ///   ZX_ERR_IO_NOT_PRESENT: The device did not respond to its I2C address.
94    ///   ZX_ERR_IO_REFUSED: The device issued a NACK before the end of a write transfer.
95    pub fn r#transfer(
96        &self,
97        mut transactions: &[Transaction],
98        ___deadline: zx::MonotonicInstant,
99    ) -> Result<DeviceTransferResult, fidl::Error> {
100        let _response = self.client.send_query::<
101            DeviceTransferRequest,
102            fidl::encoding::ResultType<DeviceTransferResponse, i32>,
103        >(
104            (transactions,),
105            0xc169f6c7849333b,
106            fidl::encoding::DynamicFlags::empty(),
107            ___deadline,
108        )?;
109        Ok(_response.map(|x| x.read_data))
110    }
111
112    /// Get the name of this I2C Device. Returns ZX_ERR_NOT_SUPPORTED if the
113    /// name is unspecified or the empty string.
114    pub fn r#get_name(
115        &self,
116        ___deadline: zx::MonotonicInstant,
117    ) -> Result<DeviceGetNameResult, fidl::Error> {
118        let _response = self.client.send_query::<
119            fidl::encoding::EmptyPayload,
120            fidl::encoding::ResultType<DeviceGetNameResponse, i32>,
121        >(
122            (),
123            0x745268a50651f102,
124            fidl::encoding::DynamicFlags::empty(),
125            ___deadline,
126        )?;
127        Ok(_response.map(|x| x.name))
128    }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl From<DeviceSynchronousProxy> for zx::Handle {
133    fn from(value: DeviceSynchronousProxy) -> Self {
134        value.into_channel().into()
135    }
136}
137
138#[cfg(target_os = "fuchsia")]
139impl From<fidl::Channel> for DeviceSynchronousProxy {
140    fn from(value: fidl::Channel) -> Self {
141        Self::new(value)
142    }
143}
144
145#[cfg(target_os = "fuchsia")]
146impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
147    type Protocol = DeviceMarker;
148
149    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
150        Self::new(value.into_channel())
151    }
152}
153
154#[derive(Debug, Clone)]
155pub struct DeviceProxy {
156    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
157}
158
159impl fidl::endpoints::Proxy for DeviceProxy {
160    type Protocol = DeviceMarker;
161
162    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
163        Self::new(inner)
164    }
165
166    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
167        self.client.into_channel().map_err(|client| Self { client })
168    }
169
170    fn as_channel(&self) -> &::fidl::AsyncChannel {
171        self.client.as_channel()
172    }
173}
174
175impl DeviceProxy {
176    /// Create a new Proxy for fuchsia.hardware.i2c/Device.
177    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
178        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
179        Self { client: fidl::client::Client::new(channel, protocol_name) }
180    }
181
182    /// Get a Stream of events from the remote end of the protocol.
183    ///
184    /// # Panics
185    ///
186    /// Panics if the event stream was already taken.
187    pub fn take_event_stream(&self) -> DeviceEventStream {
188        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
189    }
190
191    /// Issue one or more transactions to a particular I2C device.
192    ///
193    /// Each `Transaction` is performed in the order in which it appears in `transactions`. Data for
194    /// read transfers (if there are any) is returned through `read_data`, which has one entry for
195    /// each read transfer in `transactions`. Transaction processing continues until all transfers
196    /// have been completed, an error occurs, or the target issues a NACK in response to a write
197    /// transfer.
198    ///
199    /// The possible error values are:
200    ///   ZX_ERR_INVALID_ARGS: `transactions` has zero elements, `data_transfer` was not specified
201    ///     for a `Transaction`, or there was a zero-length `DataTransfer`.
202    ///   ZX_ERR_OUT_OF_RANGE: A `DataTransfer` was too large to be handled by this I2C controller.
203    ///   ZX_ERR_IO_NOT_PRESENT: The device did not respond to its I2C address.
204    ///   ZX_ERR_IO_REFUSED: The device issued a NACK before the end of a write transfer.
205    pub fn r#transfer(
206        &self,
207        mut transactions: &[Transaction],
208    ) -> fidl::client::QueryResponseFut<
209        DeviceTransferResult,
210        fidl::encoding::DefaultFuchsiaResourceDialect,
211    > {
212        DeviceProxyInterface::r#transfer(self, transactions)
213    }
214
215    /// Get the name of this I2C Device. Returns ZX_ERR_NOT_SUPPORTED if the
216    /// name is unspecified or the empty string.
217    pub fn r#get_name(
218        &self,
219    ) -> fidl::client::QueryResponseFut<
220        DeviceGetNameResult,
221        fidl::encoding::DefaultFuchsiaResourceDialect,
222    > {
223        DeviceProxyInterface::r#get_name(self)
224    }
225}
226
227impl DeviceProxyInterface for DeviceProxy {
228    type TransferResponseFut = fidl::client::QueryResponseFut<
229        DeviceTransferResult,
230        fidl::encoding::DefaultFuchsiaResourceDialect,
231    >;
232    fn r#transfer(&self, mut transactions: &[Transaction]) -> Self::TransferResponseFut {
233        fn _decode(
234            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
235        ) -> Result<DeviceTransferResult, fidl::Error> {
236            let _response = fidl::client::decode_transaction_body::<
237                fidl::encoding::ResultType<DeviceTransferResponse, i32>,
238                fidl::encoding::DefaultFuchsiaResourceDialect,
239                0xc169f6c7849333b,
240            >(_buf?)?;
241            Ok(_response.map(|x| x.read_data))
242        }
243        self.client.send_query_and_decode::<DeviceTransferRequest, DeviceTransferResult>(
244            (transactions,),
245            0xc169f6c7849333b,
246            fidl::encoding::DynamicFlags::empty(),
247            _decode,
248        )
249    }
250
251    type GetNameResponseFut = fidl::client::QueryResponseFut<
252        DeviceGetNameResult,
253        fidl::encoding::DefaultFuchsiaResourceDialect,
254    >;
255    fn r#get_name(&self) -> Self::GetNameResponseFut {
256        fn _decode(
257            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
258        ) -> Result<DeviceGetNameResult, fidl::Error> {
259            let _response = fidl::client::decode_transaction_body::<
260                fidl::encoding::ResultType<DeviceGetNameResponse, i32>,
261                fidl::encoding::DefaultFuchsiaResourceDialect,
262                0x745268a50651f102,
263            >(_buf?)?;
264            Ok(_response.map(|x| x.name))
265        }
266        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetNameResult>(
267            (),
268            0x745268a50651f102,
269            fidl::encoding::DynamicFlags::empty(),
270            _decode,
271        )
272    }
273}
274
275pub struct DeviceEventStream {
276    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
277}
278
279impl std::marker::Unpin for DeviceEventStream {}
280
281impl futures::stream::FusedStream for DeviceEventStream {
282    fn is_terminated(&self) -> bool {
283        self.event_receiver.is_terminated()
284    }
285}
286
287impl futures::Stream for DeviceEventStream {
288    type Item = Result<DeviceEvent, fidl::Error>;
289
290    fn poll_next(
291        mut self: std::pin::Pin<&mut Self>,
292        cx: &mut std::task::Context<'_>,
293    ) -> std::task::Poll<Option<Self::Item>> {
294        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
295            &mut self.event_receiver,
296            cx
297        )?) {
298            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
299            None => std::task::Poll::Ready(None),
300        }
301    }
302}
303
304#[derive(Debug)]
305pub enum DeviceEvent {}
306
307impl DeviceEvent {
308    /// Decodes a message buffer as a [`DeviceEvent`].
309    fn decode(
310        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
311    ) -> Result<DeviceEvent, fidl::Error> {
312        let (bytes, _handles) = buf.split_mut();
313        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
314        debug_assert_eq!(tx_header.tx_id, 0);
315        match tx_header.ordinal {
316            _ => Err(fidl::Error::UnknownOrdinal {
317                ordinal: tx_header.ordinal,
318                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
319            }),
320        }
321    }
322}
323
324/// A Stream of incoming requests for fuchsia.hardware.i2c/Device.
325pub struct DeviceRequestStream {
326    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
327    is_terminated: bool,
328}
329
330impl std::marker::Unpin for DeviceRequestStream {}
331
332impl futures::stream::FusedStream for DeviceRequestStream {
333    fn is_terminated(&self) -> bool {
334        self.is_terminated
335    }
336}
337
338impl fidl::endpoints::RequestStream for DeviceRequestStream {
339    type Protocol = DeviceMarker;
340    type ControlHandle = DeviceControlHandle;
341
342    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
343        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
344    }
345
346    fn control_handle(&self) -> Self::ControlHandle {
347        DeviceControlHandle { inner: self.inner.clone() }
348    }
349
350    fn into_inner(
351        self,
352    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
353    {
354        (self.inner, self.is_terminated)
355    }
356
357    fn from_inner(
358        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
359        is_terminated: bool,
360    ) -> Self {
361        Self { inner, is_terminated }
362    }
363}
364
365impl futures::Stream for DeviceRequestStream {
366    type Item = Result<DeviceRequest, fidl::Error>;
367
368    fn poll_next(
369        mut self: std::pin::Pin<&mut Self>,
370        cx: &mut std::task::Context<'_>,
371    ) -> std::task::Poll<Option<Self::Item>> {
372        let this = &mut *self;
373        if this.inner.check_shutdown(cx) {
374            this.is_terminated = true;
375            return std::task::Poll::Ready(None);
376        }
377        if this.is_terminated {
378            panic!("polled DeviceRequestStream after completion");
379        }
380        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
381            |bytes, handles| {
382                match this.inner.channel().read_etc(cx, bytes, handles) {
383                    std::task::Poll::Ready(Ok(())) => {}
384                    std::task::Poll::Pending => return std::task::Poll::Pending,
385                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
386                        this.is_terminated = true;
387                        return std::task::Poll::Ready(None);
388                    }
389                    std::task::Poll::Ready(Err(e)) => {
390                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
391                            e.into(),
392                        ))));
393                    }
394                }
395
396                // A message has been received from the channel
397                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
398
399                std::task::Poll::Ready(Some(match header.ordinal {
400                    0xc169f6c7849333b => {
401                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
402                        let mut req = fidl::new_empty!(
403                            DeviceTransferRequest,
404                            fidl::encoding::DefaultFuchsiaResourceDialect
405                        );
406                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceTransferRequest>(&header, _body_bytes, handles, &mut req)?;
407                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
408                        Ok(DeviceRequest::Transfer {
409                            transactions: req.transactions,
410
411                            responder: DeviceTransferResponder {
412                                control_handle: std::mem::ManuallyDrop::new(control_handle),
413                                tx_id: header.tx_id,
414                            },
415                        })
416                    }
417                    0x745268a50651f102 => {
418                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
419                        let mut req = fidl::new_empty!(
420                            fidl::encoding::EmptyPayload,
421                            fidl::encoding::DefaultFuchsiaResourceDialect
422                        );
423                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
424                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
425                        Ok(DeviceRequest::GetName {
426                            responder: DeviceGetNameResponder {
427                                control_handle: std::mem::ManuallyDrop::new(control_handle),
428                                tx_id: header.tx_id,
429                            },
430                        })
431                    }
432                    _ => Err(fidl::Error::UnknownOrdinal {
433                        ordinal: header.ordinal,
434                        protocol_name:
435                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
436                    }),
437                }))
438            },
439        )
440    }
441}
442
443#[derive(Debug)]
444pub enum DeviceRequest {
445    /// Issue one or more transactions to a particular I2C device.
446    ///
447    /// Each `Transaction` is performed in the order in which it appears in `transactions`. Data for
448    /// read transfers (if there are any) is returned through `read_data`, which has one entry for
449    /// each read transfer in `transactions`. Transaction processing continues until all transfers
450    /// have been completed, an error occurs, or the target issues a NACK in response to a write
451    /// transfer.
452    ///
453    /// The possible error values are:
454    ///   ZX_ERR_INVALID_ARGS: `transactions` has zero elements, `data_transfer` was not specified
455    ///     for a `Transaction`, or there was a zero-length `DataTransfer`.
456    ///   ZX_ERR_OUT_OF_RANGE: A `DataTransfer` was too large to be handled by this I2C controller.
457    ///   ZX_ERR_IO_NOT_PRESENT: The device did not respond to its I2C address.
458    ///   ZX_ERR_IO_REFUSED: The device issued a NACK before the end of a write transfer.
459    Transfer { transactions: Vec<Transaction>, responder: DeviceTransferResponder },
460    /// Get the name of this I2C Device. Returns ZX_ERR_NOT_SUPPORTED if the
461    /// name is unspecified or the empty string.
462    GetName { responder: DeviceGetNameResponder },
463}
464
465impl DeviceRequest {
466    #[allow(irrefutable_let_patterns)]
467    pub fn into_transfer(self) -> Option<(Vec<Transaction>, DeviceTransferResponder)> {
468        if let DeviceRequest::Transfer { transactions, responder } = self {
469            Some((transactions, responder))
470        } else {
471            None
472        }
473    }
474
475    #[allow(irrefutable_let_patterns)]
476    pub fn into_get_name(self) -> Option<(DeviceGetNameResponder)> {
477        if let DeviceRequest::GetName { responder } = self { Some((responder)) } else { None }
478    }
479
480    /// Name of the method defined in FIDL
481    pub fn method_name(&self) -> &'static str {
482        match *self {
483            DeviceRequest::Transfer { .. } => "transfer",
484            DeviceRequest::GetName { .. } => "get_name",
485        }
486    }
487}
488
489#[derive(Debug, Clone)]
490pub struct DeviceControlHandle {
491    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
492}
493
494impl fidl::endpoints::ControlHandle for DeviceControlHandle {
495    fn shutdown(&self) {
496        self.inner.shutdown()
497    }
498    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
499        self.inner.shutdown_with_epitaph(status)
500    }
501
502    fn is_closed(&self) -> bool {
503        self.inner.channel().is_closed()
504    }
505    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
506        self.inner.channel().on_closed()
507    }
508
509    #[cfg(target_os = "fuchsia")]
510    fn signal_peer(
511        &self,
512        clear_mask: zx::Signals,
513        set_mask: zx::Signals,
514    ) -> Result<(), zx_status::Status> {
515        use fidl::Peered;
516        self.inner.channel().signal_peer(clear_mask, set_mask)
517    }
518}
519
520impl DeviceControlHandle {}
521
522#[must_use = "FIDL methods require a response to be sent"]
523#[derive(Debug)]
524pub struct DeviceTransferResponder {
525    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
526    tx_id: u32,
527}
528
529/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
530/// if the responder is dropped without sending a response, so that the client
531/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
532impl std::ops::Drop for DeviceTransferResponder {
533    fn drop(&mut self) {
534        self.control_handle.shutdown();
535        // Safety: drops once, never accessed again
536        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
537    }
538}
539
540impl fidl::endpoints::Responder for DeviceTransferResponder {
541    type ControlHandle = DeviceControlHandle;
542
543    fn control_handle(&self) -> &DeviceControlHandle {
544        &self.control_handle
545    }
546
547    fn drop_without_shutdown(mut self) {
548        // Safety: drops once, never accessed again due to mem::forget
549        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
550        // Prevent Drop from running (which would shut down the channel)
551        std::mem::forget(self);
552    }
553}
554
555impl DeviceTransferResponder {
556    /// Sends a response to the FIDL transaction.
557    ///
558    /// Sets the channel to shutdown if an error occurs.
559    pub fn send(self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
560        let _result = self.send_raw(result);
561        if _result.is_err() {
562            self.control_handle.shutdown();
563        }
564        self.drop_without_shutdown();
565        _result
566    }
567
568    /// Similar to "send" but does not shutdown the channel if an error occurs.
569    pub fn send_no_shutdown_on_err(
570        self,
571        mut result: Result<&[Vec<u8>], i32>,
572    ) -> Result<(), fidl::Error> {
573        let _result = self.send_raw(result);
574        self.drop_without_shutdown();
575        _result
576    }
577
578    fn send_raw(&self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
579        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceTransferResponse, i32>>(
580            result.map(|read_data| (read_data,)),
581            self.tx_id,
582            0xc169f6c7849333b,
583            fidl::encoding::DynamicFlags::empty(),
584        )
585    }
586}
587
588#[must_use = "FIDL methods require a response to be sent"]
589#[derive(Debug)]
590pub struct DeviceGetNameResponder {
591    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
592    tx_id: u32,
593}
594
595/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
596/// if the responder is dropped without sending a response, so that the client
597/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
598impl std::ops::Drop for DeviceGetNameResponder {
599    fn drop(&mut self) {
600        self.control_handle.shutdown();
601        // Safety: drops once, never accessed again
602        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
603    }
604}
605
606impl fidl::endpoints::Responder for DeviceGetNameResponder {
607    type ControlHandle = DeviceControlHandle;
608
609    fn control_handle(&self) -> &DeviceControlHandle {
610        &self.control_handle
611    }
612
613    fn drop_without_shutdown(mut self) {
614        // Safety: drops once, never accessed again due to mem::forget
615        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
616        // Prevent Drop from running (which would shut down the channel)
617        std::mem::forget(self);
618    }
619}
620
621impl DeviceGetNameResponder {
622    /// Sends a response to the FIDL transaction.
623    ///
624    /// Sets the channel to shutdown if an error occurs.
625    pub fn send(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
626        let _result = self.send_raw(result);
627        if _result.is_err() {
628            self.control_handle.shutdown();
629        }
630        self.drop_without_shutdown();
631        _result
632    }
633
634    /// Similar to "send" but does not shutdown the channel if an error occurs.
635    pub fn send_no_shutdown_on_err(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
636        let _result = self.send_raw(result);
637        self.drop_without_shutdown();
638        _result
639    }
640
641    fn send_raw(&self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
642        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceGetNameResponse, i32>>(
643            result.map(|name| (name,)),
644            self.tx_id,
645            0x745268a50651f102,
646            fidl::encoding::DynamicFlags::empty(),
647        )
648    }
649}
650
651#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
652pub struct ServiceMarker;
653
654#[cfg(target_os = "fuchsia")]
655impl fidl::endpoints::ServiceMarker for ServiceMarker {
656    type Proxy = ServiceProxy;
657    type Request = ServiceRequest;
658    const SERVICE_NAME: &'static str = "fuchsia.hardware.i2c.Service";
659}
660
661/// A request for one of the member protocols of Service.
662///
663#[cfg(target_os = "fuchsia")]
664pub enum ServiceRequest {
665    Device(DeviceRequestStream),
666}
667
668#[cfg(target_os = "fuchsia")]
669impl fidl::endpoints::ServiceRequest for ServiceRequest {
670    type Service = ServiceMarker;
671
672    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
673        match name {
674            "device" => Self::Device(
675                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
676            ),
677            _ => panic!("no such member protocol name for service Service"),
678        }
679    }
680
681    fn member_names() -> &'static [&'static str] {
682        &["device"]
683    }
684}
685#[cfg(target_os = "fuchsia")]
686pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
687
688#[cfg(target_os = "fuchsia")]
689impl fidl::endpoints::ServiceProxy for ServiceProxy {
690    type Service = ServiceMarker;
691
692    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
693        Self(opener)
694    }
695}
696
697#[cfg(target_os = "fuchsia")]
698impl ServiceProxy {
699    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
700        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
701        self.connect_channel_to_device(server_end)?;
702        Ok(proxy)
703    }
704
705    /// Like `connect_to_device`, but returns a sync proxy.
706    /// See [`Self::connect_to_device`] for more details.
707    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
708        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
709        self.connect_channel_to_device(server_end)?;
710        Ok(proxy)
711    }
712
713    /// Like `connect_to_device`, but accepts a server end.
714    /// See [`Self::connect_to_device`] for more details.
715    pub fn connect_channel_to_device(
716        &self,
717        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
718    ) -> Result<(), fidl::Error> {
719        self.0.open_member("device", server_end.into_channel())
720    }
721
722    pub fn instance_name(&self) -> &str {
723        self.0.instance_name()
724    }
725}
726
727mod internal {
728    use super::*;
729}