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