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