Skip to main content

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