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