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 fidl::endpoints::ControlHandle for ExampleControlHandle {
511    fn shutdown(&self) {
512        self.inner.shutdown()
513    }
514
515    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
516        self.inner.shutdown_with_epitaph(status)
517    }
518
519    fn is_closed(&self) -> bool {
520        self.inner.channel().is_closed()
521    }
522    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
523        self.inner.channel().on_closed()
524    }
525
526    #[cfg(target_os = "fuchsia")]
527    fn signal_peer(
528        &self,
529        clear_mask: zx::Signals,
530        set_mask: zx::Signals,
531    ) -> Result<(), zx_status::Status> {
532        use fidl::Peered;
533        self.inner.channel().signal_peer(clear_mask, set_mask)
534    }
535}
536
537impl ExampleControlHandle {}
538
539#[must_use = "FIDL methods require a response to be sent"]
540#[derive(Debug)]
541pub struct ExampleGetMonotonicResponder {
542    control_handle: std::mem::ManuallyDrop<ExampleControlHandle>,
543    tx_id: u32,
544}
545
546/// Set the the channel to be shutdown (see [`ExampleControlHandle::shutdown`])
547/// if the responder is dropped without sending a response, so that the client
548/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
549impl std::ops::Drop for ExampleGetMonotonicResponder {
550    fn drop(&mut self) {
551        self.control_handle.shutdown();
552        // Safety: drops once, never accessed again
553        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
554    }
555}
556
557impl fidl::endpoints::Responder for ExampleGetMonotonicResponder {
558    type ControlHandle = ExampleControlHandle;
559
560    fn control_handle(&self) -> &ExampleControlHandle {
561        &self.control_handle
562    }
563
564    fn drop_without_shutdown(mut self) {
565        // Safety: drops once, never accessed again due to mem::forget
566        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
567        // Prevent Drop from running (which would shut down the channel)
568        std::mem::forget(self);
569    }
570}
571
572impl ExampleGetMonotonicResponder {
573    /// Sends a response to the FIDL transaction.
574    ///
575    /// Sets the channel to shutdown if an error occurs.
576    pub fn send(self, mut time: i64) -> Result<(), fidl::Error> {
577        let _result = self.send_raw(time);
578        if _result.is_err() {
579            self.control_handle.shutdown();
580        }
581        self.drop_without_shutdown();
582        _result
583    }
584
585    /// Similar to "send" but does not shutdown the channel if an error occurs.
586    pub fn send_no_shutdown_on_err(self, mut time: i64) -> Result<(), fidl::Error> {
587        let _result = self.send_raw(time);
588        self.drop_without_shutdown();
589        _result
590    }
591
592    fn send_raw(&self, mut time: i64) -> Result<(), fidl::Error> {
593        self.control_handle.inner.send::<ExampleGetMonotonicResponse>(
594            (time,),
595            self.tx_id,
596            0xc8bbde6196b6568,
597            fidl::encoding::DynamicFlags::empty(),
598        )
599    }
600}
601
602#[must_use = "FIDL methods require a response to be sent"]
603#[derive(Debug)]
604pub struct ExampleWaitUntilResponder {
605    control_handle: std::mem::ManuallyDrop<ExampleControlHandle>,
606    tx_id: u32,
607}
608
609/// Set the the channel to be shutdown (see [`ExampleControlHandle::shutdown`])
610/// if the responder is dropped without sending a response, so that the client
611/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
612impl std::ops::Drop for ExampleWaitUntilResponder {
613    fn drop(&mut self) {
614        self.control_handle.shutdown();
615        // Safety: drops once, never accessed again
616        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
617    }
618}
619
620impl fidl::endpoints::Responder for ExampleWaitUntilResponder {
621    type ControlHandle = ExampleControlHandle;
622
623    fn control_handle(&self) -> &ExampleControlHandle {
624        &self.control_handle
625    }
626
627    fn drop_without_shutdown(mut self) {
628        // Safety: drops once, never accessed again due to mem::forget
629        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
630        // Prevent Drop from running (which would shut down the channel)
631        std::mem::forget(self);
632    }
633}
634
635impl ExampleWaitUntilResponder {
636    /// Sends a response to the FIDL transaction.
637    ///
638    /// Sets the channel to shutdown if an error occurs.
639    pub fn send(self) -> Result<(), fidl::Error> {
640        let _result = self.send_raw();
641        if _result.is_err() {
642            self.control_handle.shutdown();
643        }
644        self.drop_without_shutdown();
645        _result
646    }
647
648    /// Similar to "send" but does not shutdown the channel if an error occurs.
649    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
650        let _result = self.send_raw();
651        self.drop_without_shutdown();
652        _result
653    }
654
655    fn send_raw(&self) -> Result<(), fidl::Error> {
656        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
657            (),
658            self.tx_id,
659            0x60e188ba3d61ed0a,
660            fidl::encoding::DynamicFlags::empty(),
661        )
662    }
663}
664
665#[must_use = "FIDL methods require a response to be sent"]
666#[derive(Debug)]
667pub struct ExampleWaitForResponder {
668    control_handle: std::mem::ManuallyDrop<ExampleControlHandle>,
669    tx_id: u32,
670}
671
672/// Set the the channel to be shutdown (see [`ExampleControlHandle::shutdown`])
673/// if the responder is dropped without sending a response, so that the client
674/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
675impl std::ops::Drop for ExampleWaitForResponder {
676    fn drop(&mut self) {
677        self.control_handle.shutdown();
678        // Safety: drops once, never accessed again
679        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
680    }
681}
682
683impl fidl::endpoints::Responder for ExampleWaitForResponder {
684    type ControlHandle = ExampleControlHandle;
685
686    fn control_handle(&self) -> &ExampleControlHandle {
687        &self.control_handle
688    }
689
690    fn drop_without_shutdown(mut self) {
691        // Safety: drops once, never accessed again due to mem::forget
692        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
693        // Prevent Drop from running (which would shut down the channel)
694        std::mem::forget(self);
695    }
696}
697
698impl ExampleWaitForResponder {
699    /// Sends a response to the FIDL transaction.
700    ///
701    /// Sets the channel to shutdown if an error occurs.
702    pub fn send(self) -> Result<(), fidl::Error> {
703        let _result = self.send_raw();
704        if _result.is_err() {
705            self.control_handle.shutdown();
706        }
707        self.drop_without_shutdown();
708        _result
709    }
710
711    /// Similar to "send" but does not shutdown the channel if an error occurs.
712    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
713        let _result = self.send_raw();
714        self.drop_without_shutdown();
715        _result
716    }
717
718    fn send_raw(&self) -> Result<(), fidl::Error> {
719        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
720            (),
721            self.tx_id,
722            0x5a6de7cbba3b5b1e,
723            fidl::encoding::DynamicFlags::empty(),
724        )
725    }
726}
727
728mod internal {
729    use super::*;
730}