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 {
478            Some((responder))
479        } else {
480            None
481        }
482    }
483
484    /// Name of the method defined in FIDL
485    pub fn method_name(&self) -> &'static str {
486        match *self {
487            DeviceRequest::Transfer { .. } => "transfer",
488            DeviceRequest::GetName { .. } => "get_name",
489        }
490    }
491}
492
493#[derive(Debug, Clone)]
494pub struct DeviceControlHandle {
495    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
496}
497
498impl fidl::endpoints::ControlHandle for DeviceControlHandle {
499    fn shutdown(&self) {
500        self.inner.shutdown()
501    }
502    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
503        self.inner.shutdown_with_epitaph(status)
504    }
505
506    fn is_closed(&self) -> bool {
507        self.inner.channel().is_closed()
508    }
509    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
510        self.inner.channel().on_closed()
511    }
512
513    #[cfg(target_os = "fuchsia")]
514    fn signal_peer(
515        &self,
516        clear_mask: zx::Signals,
517        set_mask: zx::Signals,
518    ) -> Result<(), zx_status::Status> {
519        use fidl::Peered;
520        self.inner.channel().signal_peer(clear_mask, set_mask)
521    }
522}
523
524impl DeviceControlHandle {}
525
526#[must_use = "FIDL methods require a response to be sent"]
527#[derive(Debug)]
528pub struct DeviceTransferResponder {
529    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
530    tx_id: u32,
531}
532
533/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
534/// if the responder is dropped without sending a response, so that the client
535/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
536impl std::ops::Drop for DeviceTransferResponder {
537    fn drop(&mut self) {
538        self.control_handle.shutdown();
539        // Safety: drops once, never accessed again
540        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
541    }
542}
543
544impl fidl::endpoints::Responder for DeviceTransferResponder {
545    type ControlHandle = DeviceControlHandle;
546
547    fn control_handle(&self) -> &DeviceControlHandle {
548        &self.control_handle
549    }
550
551    fn drop_without_shutdown(mut self) {
552        // Safety: drops once, never accessed again due to mem::forget
553        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
554        // Prevent Drop from running (which would shut down the channel)
555        std::mem::forget(self);
556    }
557}
558
559impl DeviceTransferResponder {
560    /// Sends a response to the FIDL transaction.
561    ///
562    /// Sets the channel to shutdown if an error occurs.
563    pub fn send(self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
564        let _result = self.send_raw(result);
565        if _result.is_err() {
566            self.control_handle.shutdown();
567        }
568        self.drop_without_shutdown();
569        _result
570    }
571
572    /// Similar to "send" but does not shutdown the channel if an error occurs.
573    pub fn send_no_shutdown_on_err(
574        self,
575        mut result: Result<&[Vec<u8>], i32>,
576    ) -> Result<(), fidl::Error> {
577        let _result = self.send_raw(result);
578        self.drop_without_shutdown();
579        _result
580    }
581
582    fn send_raw(&self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
583        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceTransferResponse, i32>>(
584            result.map(|read_data| (read_data,)),
585            self.tx_id,
586            0xc169f6c7849333b,
587            fidl::encoding::DynamicFlags::empty(),
588        )
589    }
590}
591
592#[must_use = "FIDL methods require a response to be sent"]
593#[derive(Debug)]
594pub struct DeviceGetNameResponder {
595    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
596    tx_id: u32,
597}
598
599/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
600/// if the responder is dropped without sending a response, so that the client
601/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
602impl std::ops::Drop for DeviceGetNameResponder {
603    fn drop(&mut self) {
604        self.control_handle.shutdown();
605        // Safety: drops once, never accessed again
606        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
607    }
608}
609
610impl fidl::endpoints::Responder for DeviceGetNameResponder {
611    type ControlHandle = DeviceControlHandle;
612
613    fn control_handle(&self) -> &DeviceControlHandle {
614        &self.control_handle
615    }
616
617    fn drop_without_shutdown(mut self) {
618        // Safety: drops once, never accessed again due to mem::forget
619        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
620        // Prevent Drop from running (which would shut down the channel)
621        std::mem::forget(self);
622    }
623}
624
625impl DeviceGetNameResponder {
626    /// Sends a response to the FIDL transaction.
627    ///
628    /// Sets the channel to shutdown if an error occurs.
629    pub fn send(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
630        let _result = self.send_raw(result);
631        if _result.is_err() {
632            self.control_handle.shutdown();
633        }
634        self.drop_without_shutdown();
635        _result
636    }
637
638    /// Similar to "send" but does not shutdown the channel if an error occurs.
639    pub fn send_no_shutdown_on_err(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
640        let _result = self.send_raw(result);
641        self.drop_without_shutdown();
642        _result
643    }
644
645    fn send_raw(&self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
646        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceGetNameResponse, i32>>(
647            result.map(|name| (name,)),
648            self.tx_id,
649            0x745268a50651f102,
650            fidl::encoding::DynamicFlags::empty(),
651        )
652    }
653}
654
655#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
656pub struct ServiceMarker;
657
658#[cfg(target_os = "fuchsia")]
659impl fidl::endpoints::ServiceMarker for ServiceMarker {
660    type Proxy = ServiceProxy;
661    type Request = ServiceRequest;
662    const SERVICE_NAME: &'static str = "fuchsia.hardware.i2c.Service";
663}
664
665/// A request for one of the member protocols of Service.
666///
667#[cfg(target_os = "fuchsia")]
668pub enum ServiceRequest {
669    Device(DeviceRequestStream),
670}
671
672#[cfg(target_os = "fuchsia")]
673impl fidl::endpoints::ServiceRequest for ServiceRequest {
674    type Service = ServiceMarker;
675
676    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
677        match name {
678            "device" => Self::Device(
679                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
680            ),
681            _ => panic!("no such member protocol name for service Service"),
682        }
683    }
684
685    fn member_names() -> &'static [&'static str] {
686        &["device"]
687    }
688}
689#[cfg(target_os = "fuchsia")]
690pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
691
692#[cfg(target_os = "fuchsia")]
693impl fidl::endpoints::ServiceProxy for ServiceProxy {
694    type Service = ServiceMarker;
695
696    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
697        Self(opener)
698    }
699}
700
701#[cfg(target_os = "fuchsia")]
702impl ServiceProxy {
703    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
704        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
705        self.connect_channel_to_device(server_end)?;
706        Ok(proxy)
707    }
708
709    /// Like `connect_to_device`, but returns a sync proxy.
710    /// See [`Self::connect_to_device`] for more details.
711    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
712        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
713        self.connect_channel_to_device(server_end)?;
714        Ok(proxy)
715    }
716
717    /// Like `connect_to_device`, but accepts a server end.
718    /// See [`Self::connect_to_device`] for more details.
719    pub fn connect_channel_to_device(
720        &self,
721        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
722    ) -> Result<(), fidl::Error> {
723        self.0.open_member("device", server_end.into_channel())
724    }
725
726    pub fn instance_name(&self) -> &str {
727        self.0.instance_name()
728    }
729}
730
731mod internal {
732    use super::*;
733}