fidl_fuchsia_examples_inspect/
fidl_fuchsia_examples_inspect.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_examples_inspect__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct FizzBuzzMarker;
16
17impl fidl::endpoints::ProtocolMarker for FizzBuzzMarker {
18    type Proxy = FizzBuzzProxy;
19    type RequestStream = FizzBuzzRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = FizzBuzzSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.examples.inspect.FizzBuzz";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for FizzBuzzMarker {}
26
27pub trait FizzBuzzProxyInterface: Send + Sync {
28    type ExecuteResponseFut: std::future::Future<Output = Result<String, fidl::Error>> + Send;
29    fn r#execute(&self, count: u32) -> Self::ExecuteResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct FizzBuzzSynchronousProxy {
34    client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for FizzBuzzSynchronousProxy {
39    type Proxy = FizzBuzzProxy;
40    type Protocol = FizzBuzzMarker;
41
42    fn from_channel(inner: fidl::Channel) -> Self {
43        Self::new(inner)
44    }
45
46    fn into_channel(self) -> fidl::Channel {
47        self.client.into_channel()
48    }
49
50    fn as_channel(&self) -> &fidl::Channel {
51        self.client.as_channel()
52    }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl FizzBuzzSynchronousProxy {
57    pub fn new(channel: fidl::Channel) -> Self {
58        let protocol_name = <FizzBuzzMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60    }
61
62    pub fn into_channel(self) -> fidl::Channel {
63        self.client.into_channel()
64    }
65
66    /// Waits until an event arrives and returns it. It is safe for other
67    /// threads to make concurrent requests while waiting for an event.
68    pub fn wait_for_event(
69        &self,
70        deadline: zx::MonotonicInstant,
71    ) -> Result<FizzBuzzEvent, fidl::Error> {
72        FizzBuzzEvent::decode(self.client.wait_for_event(deadline)?)
73    }
74
75    pub fn r#execute(
76        &self,
77        mut count: u32,
78        ___deadline: zx::MonotonicInstant,
79    ) -> Result<String, fidl::Error> {
80        let _response = self.client.send_query::<FizzBuzzExecuteRequest, FizzBuzzExecuteResponse>(
81            (count,),
82            0x207cbeb002df3833,
83            fidl::encoding::DynamicFlags::empty(),
84            ___deadline,
85        )?;
86        Ok(_response.response)
87    }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl From<FizzBuzzSynchronousProxy> for zx::Handle {
92    fn from(value: FizzBuzzSynchronousProxy) -> Self {
93        value.into_channel().into()
94    }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl From<fidl::Channel> for FizzBuzzSynchronousProxy {
99    fn from(value: fidl::Channel) -> Self {
100        Self::new(value)
101    }
102}
103
104#[cfg(target_os = "fuchsia")]
105impl fidl::endpoints::FromClient for FizzBuzzSynchronousProxy {
106    type Protocol = FizzBuzzMarker;
107
108    fn from_client(value: fidl::endpoints::ClientEnd<FizzBuzzMarker>) -> Self {
109        Self::new(value.into_channel())
110    }
111}
112
113#[derive(Debug, Clone)]
114pub struct FizzBuzzProxy {
115    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
116}
117
118impl fidl::endpoints::Proxy for FizzBuzzProxy {
119    type Protocol = FizzBuzzMarker;
120
121    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
122        Self::new(inner)
123    }
124
125    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
126        self.client.into_channel().map_err(|client| Self { client })
127    }
128
129    fn as_channel(&self) -> &::fidl::AsyncChannel {
130        self.client.as_channel()
131    }
132}
133
134impl FizzBuzzProxy {
135    /// Create a new Proxy for fuchsia.examples.inspect/FizzBuzz.
136    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
137        let protocol_name = <FizzBuzzMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
138        Self { client: fidl::client::Client::new(channel, protocol_name) }
139    }
140
141    /// Get a Stream of events from the remote end of the protocol.
142    ///
143    /// # Panics
144    ///
145    /// Panics if the event stream was already taken.
146    pub fn take_event_stream(&self) -> FizzBuzzEventStream {
147        FizzBuzzEventStream { event_receiver: self.client.take_event_receiver() }
148    }
149
150    pub fn r#execute(
151        &self,
152        mut count: u32,
153    ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
154        FizzBuzzProxyInterface::r#execute(self, count)
155    }
156}
157
158impl FizzBuzzProxyInterface for FizzBuzzProxy {
159    type ExecuteResponseFut =
160        fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
161    fn r#execute(&self, mut count: u32) -> Self::ExecuteResponseFut {
162        fn _decode(
163            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
164        ) -> Result<String, fidl::Error> {
165            let _response = fidl::client::decode_transaction_body::<
166                FizzBuzzExecuteResponse,
167                fidl::encoding::DefaultFuchsiaResourceDialect,
168                0x207cbeb002df3833,
169            >(_buf?)?;
170            Ok(_response.response)
171        }
172        self.client.send_query_and_decode::<FizzBuzzExecuteRequest, String>(
173            (count,),
174            0x207cbeb002df3833,
175            fidl::encoding::DynamicFlags::empty(),
176            _decode,
177        )
178    }
179}
180
181pub struct FizzBuzzEventStream {
182    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
183}
184
185impl std::marker::Unpin for FizzBuzzEventStream {}
186
187impl futures::stream::FusedStream for FizzBuzzEventStream {
188    fn is_terminated(&self) -> bool {
189        self.event_receiver.is_terminated()
190    }
191}
192
193impl futures::Stream for FizzBuzzEventStream {
194    type Item = Result<FizzBuzzEvent, fidl::Error>;
195
196    fn poll_next(
197        mut self: std::pin::Pin<&mut Self>,
198        cx: &mut std::task::Context<'_>,
199    ) -> std::task::Poll<Option<Self::Item>> {
200        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
201            &mut self.event_receiver,
202            cx
203        )?) {
204            Some(buf) => std::task::Poll::Ready(Some(FizzBuzzEvent::decode(buf))),
205            None => std::task::Poll::Ready(None),
206        }
207    }
208}
209
210#[derive(Debug)]
211pub enum FizzBuzzEvent {}
212
213impl FizzBuzzEvent {
214    /// Decodes a message buffer as a [`FizzBuzzEvent`].
215    fn decode(
216        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
217    ) -> Result<FizzBuzzEvent, fidl::Error> {
218        let (bytes, _handles) = buf.split_mut();
219        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
220        debug_assert_eq!(tx_header.tx_id, 0);
221        match tx_header.ordinal {
222            _ => Err(fidl::Error::UnknownOrdinal {
223                ordinal: tx_header.ordinal,
224                protocol_name: <FizzBuzzMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
225            }),
226        }
227    }
228}
229
230/// A Stream of incoming requests for fuchsia.examples.inspect/FizzBuzz.
231pub struct FizzBuzzRequestStream {
232    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
233    is_terminated: bool,
234}
235
236impl std::marker::Unpin for FizzBuzzRequestStream {}
237
238impl futures::stream::FusedStream for FizzBuzzRequestStream {
239    fn is_terminated(&self) -> bool {
240        self.is_terminated
241    }
242}
243
244impl fidl::endpoints::RequestStream for FizzBuzzRequestStream {
245    type Protocol = FizzBuzzMarker;
246    type ControlHandle = FizzBuzzControlHandle;
247
248    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
249        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
250    }
251
252    fn control_handle(&self) -> Self::ControlHandle {
253        FizzBuzzControlHandle { inner: self.inner.clone() }
254    }
255
256    fn into_inner(
257        self,
258    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
259    {
260        (self.inner, self.is_terminated)
261    }
262
263    fn from_inner(
264        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
265        is_terminated: bool,
266    ) -> Self {
267        Self { inner, is_terminated }
268    }
269}
270
271impl futures::Stream for FizzBuzzRequestStream {
272    type Item = Result<FizzBuzzRequest, fidl::Error>;
273
274    fn poll_next(
275        mut self: std::pin::Pin<&mut Self>,
276        cx: &mut std::task::Context<'_>,
277    ) -> std::task::Poll<Option<Self::Item>> {
278        let this = &mut *self;
279        if this.inner.check_shutdown(cx) {
280            this.is_terminated = true;
281            return std::task::Poll::Ready(None);
282        }
283        if this.is_terminated {
284            panic!("polled FizzBuzzRequestStream after completion");
285        }
286        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
287            |bytes, handles| {
288                match this.inner.channel().read_etc(cx, bytes, handles) {
289                    std::task::Poll::Ready(Ok(())) => {}
290                    std::task::Poll::Pending => return std::task::Poll::Pending,
291                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
292                        this.is_terminated = true;
293                        return std::task::Poll::Ready(None);
294                    }
295                    std::task::Poll::Ready(Err(e)) => {
296                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
297                            e.into(),
298                        ))))
299                    }
300                }
301
302                // A message has been received from the channel
303                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
304
305                std::task::Poll::Ready(Some(match header.ordinal {
306                    0x207cbeb002df3833 => {
307                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
308                        let mut req = fidl::new_empty!(
309                            FizzBuzzExecuteRequest,
310                            fidl::encoding::DefaultFuchsiaResourceDialect
311                        );
312                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<FizzBuzzExecuteRequest>(&header, _body_bytes, handles, &mut req)?;
313                        let control_handle = FizzBuzzControlHandle { inner: this.inner.clone() };
314                        Ok(FizzBuzzRequest::Execute {
315                            count: req.count,
316
317                            responder: FizzBuzzExecuteResponder {
318                                control_handle: std::mem::ManuallyDrop::new(control_handle),
319                                tx_id: header.tx_id,
320                            },
321                        })
322                    }
323                    _ => Err(fidl::Error::UnknownOrdinal {
324                        ordinal: header.ordinal,
325                        protocol_name:
326                            <FizzBuzzMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
327                    }),
328                }))
329            },
330        )
331    }
332}
333
334#[derive(Debug)]
335pub enum FizzBuzzRequest {
336    Execute { count: u32, responder: FizzBuzzExecuteResponder },
337}
338
339impl FizzBuzzRequest {
340    #[allow(irrefutable_let_patterns)]
341    pub fn into_execute(self) -> Option<(u32, FizzBuzzExecuteResponder)> {
342        if let FizzBuzzRequest::Execute { count, responder } = self {
343            Some((count, responder))
344        } else {
345            None
346        }
347    }
348
349    /// Name of the method defined in FIDL
350    pub fn method_name(&self) -> &'static str {
351        match *self {
352            FizzBuzzRequest::Execute { .. } => "execute",
353        }
354    }
355}
356
357#[derive(Debug, Clone)]
358pub struct FizzBuzzControlHandle {
359    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
360}
361
362impl fidl::endpoints::ControlHandle for FizzBuzzControlHandle {
363    fn shutdown(&self) {
364        self.inner.shutdown()
365    }
366    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
367        self.inner.shutdown_with_epitaph(status)
368    }
369
370    fn is_closed(&self) -> bool {
371        self.inner.channel().is_closed()
372    }
373    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
374        self.inner.channel().on_closed()
375    }
376
377    #[cfg(target_os = "fuchsia")]
378    fn signal_peer(
379        &self,
380        clear_mask: zx::Signals,
381        set_mask: zx::Signals,
382    ) -> Result<(), zx_status::Status> {
383        use fidl::Peered;
384        self.inner.channel().signal_peer(clear_mask, set_mask)
385    }
386}
387
388impl FizzBuzzControlHandle {}
389
390#[must_use = "FIDL methods require a response to be sent"]
391#[derive(Debug)]
392pub struct FizzBuzzExecuteResponder {
393    control_handle: std::mem::ManuallyDrop<FizzBuzzControlHandle>,
394    tx_id: u32,
395}
396
397/// Set the the channel to be shutdown (see [`FizzBuzzControlHandle::shutdown`])
398/// if the responder is dropped without sending a response, so that the client
399/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
400impl std::ops::Drop for FizzBuzzExecuteResponder {
401    fn drop(&mut self) {
402        self.control_handle.shutdown();
403        // Safety: drops once, never accessed again
404        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
405    }
406}
407
408impl fidl::endpoints::Responder for FizzBuzzExecuteResponder {
409    type ControlHandle = FizzBuzzControlHandle;
410
411    fn control_handle(&self) -> &FizzBuzzControlHandle {
412        &self.control_handle
413    }
414
415    fn drop_without_shutdown(mut self) {
416        // Safety: drops once, never accessed again due to mem::forget
417        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
418        // Prevent Drop from running (which would shut down the channel)
419        std::mem::forget(self);
420    }
421}
422
423impl FizzBuzzExecuteResponder {
424    /// Sends a response to the FIDL transaction.
425    ///
426    /// Sets the channel to shutdown if an error occurs.
427    pub fn send(self, mut response: &str) -> Result<(), fidl::Error> {
428        let _result = self.send_raw(response);
429        if _result.is_err() {
430            self.control_handle.shutdown();
431        }
432        self.drop_without_shutdown();
433        _result
434    }
435
436    /// Similar to "send" but does not shutdown the channel if an error occurs.
437    pub fn send_no_shutdown_on_err(self, mut response: &str) -> Result<(), fidl::Error> {
438        let _result = self.send_raw(response);
439        self.drop_without_shutdown();
440        _result
441    }
442
443    fn send_raw(&self, mut response: &str) -> Result<(), fidl::Error> {
444        self.control_handle.inner.send::<FizzBuzzExecuteResponse>(
445            (response,),
446            self.tx_id,
447            0x207cbeb002df3833,
448            fidl::encoding::DynamicFlags::empty(),
449        )
450    }
451}
452
453#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
454pub struct ReverserMarker;
455
456impl fidl::endpoints::ProtocolMarker for ReverserMarker {
457    type Proxy = ReverserProxy;
458    type RequestStream = ReverserRequestStream;
459    #[cfg(target_os = "fuchsia")]
460    type SynchronousProxy = ReverserSynchronousProxy;
461
462    const DEBUG_NAME: &'static str = "fuchsia.examples.inspect.Reverser";
463}
464impl fidl::endpoints::DiscoverableProtocolMarker for ReverserMarker {}
465
466pub trait ReverserProxyInterface: Send + Sync {
467    type ReverseResponseFut: std::future::Future<Output = Result<String, fidl::Error>> + Send;
468    fn r#reverse(&self, input: &str) -> Self::ReverseResponseFut;
469}
470#[derive(Debug)]
471#[cfg(target_os = "fuchsia")]
472pub struct ReverserSynchronousProxy {
473    client: fidl::client::sync::Client,
474}
475
476#[cfg(target_os = "fuchsia")]
477impl fidl::endpoints::SynchronousProxy for ReverserSynchronousProxy {
478    type Proxy = ReverserProxy;
479    type Protocol = ReverserMarker;
480
481    fn from_channel(inner: fidl::Channel) -> Self {
482        Self::new(inner)
483    }
484
485    fn into_channel(self) -> fidl::Channel {
486        self.client.into_channel()
487    }
488
489    fn as_channel(&self) -> &fidl::Channel {
490        self.client.as_channel()
491    }
492}
493
494#[cfg(target_os = "fuchsia")]
495impl ReverserSynchronousProxy {
496    pub fn new(channel: fidl::Channel) -> Self {
497        let protocol_name = <ReverserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
498        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
499    }
500
501    pub fn into_channel(self) -> fidl::Channel {
502        self.client.into_channel()
503    }
504
505    /// Waits until an event arrives and returns it. It is safe for other
506    /// threads to make concurrent requests while waiting for an event.
507    pub fn wait_for_event(
508        &self,
509        deadline: zx::MonotonicInstant,
510    ) -> Result<ReverserEvent, fidl::Error> {
511        ReverserEvent::decode(self.client.wait_for_event(deadline)?)
512    }
513
514    pub fn r#reverse(
515        &self,
516        mut input: &str,
517        ___deadline: zx::MonotonicInstant,
518    ) -> Result<String, fidl::Error> {
519        let _response = self.client.send_query::<ReverserReverseRequest, ReverserReverseResponse>(
520            (input,),
521            0x481eccb3af87ff3e,
522            fidl::encoding::DynamicFlags::empty(),
523            ___deadline,
524        )?;
525        Ok(_response.response)
526    }
527}
528
529#[cfg(target_os = "fuchsia")]
530impl From<ReverserSynchronousProxy> for zx::Handle {
531    fn from(value: ReverserSynchronousProxy) -> Self {
532        value.into_channel().into()
533    }
534}
535
536#[cfg(target_os = "fuchsia")]
537impl From<fidl::Channel> for ReverserSynchronousProxy {
538    fn from(value: fidl::Channel) -> Self {
539        Self::new(value)
540    }
541}
542
543#[cfg(target_os = "fuchsia")]
544impl fidl::endpoints::FromClient for ReverserSynchronousProxy {
545    type Protocol = ReverserMarker;
546
547    fn from_client(value: fidl::endpoints::ClientEnd<ReverserMarker>) -> Self {
548        Self::new(value.into_channel())
549    }
550}
551
552#[derive(Debug, Clone)]
553pub struct ReverserProxy {
554    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
555}
556
557impl fidl::endpoints::Proxy for ReverserProxy {
558    type Protocol = ReverserMarker;
559
560    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
561        Self::new(inner)
562    }
563
564    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
565        self.client.into_channel().map_err(|client| Self { client })
566    }
567
568    fn as_channel(&self) -> &::fidl::AsyncChannel {
569        self.client.as_channel()
570    }
571}
572
573impl ReverserProxy {
574    /// Create a new Proxy for fuchsia.examples.inspect/Reverser.
575    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
576        let protocol_name = <ReverserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
577        Self { client: fidl::client::Client::new(channel, protocol_name) }
578    }
579
580    /// Get a Stream of events from the remote end of the protocol.
581    ///
582    /// # Panics
583    ///
584    /// Panics if the event stream was already taken.
585    pub fn take_event_stream(&self) -> ReverserEventStream {
586        ReverserEventStream { event_receiver: self.client.take_event_receiver() }
587    }
588
589    pub fn r#reverse(
590        &self,
591        mut input: &str,
592    ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
593        ReverserProxyInterface::r#reverse(self, input)
594    }
595}
596
597impl ReverserProxyInterface for ReverserProxy {
598    type ReverseResponseFut =
599        fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
600    fn r#reverse(&self, mut input: &str) -> Self::ReverseResponseFut {
601        fn _decode(
602            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
603        ) -> Result<String, fidl::Error> {
604            let _response = fidl::client::decode_transaction_body::<
605                ReverserReverseResponse,
606                fidl::encoding::DefaultFuchsiaResourceDialect,
607                0x481eccb3af87ff3e,
608            >(_buf?)?;
609            Ok(_response.response)
610        }
611        self.client.send_query_and_decode::<ReverserReverseRequest, String>(
612            (input,),
613            0x481eccb3af87ff3e,
614            fidl::encoding::DynamicFlags::empty(),
615            _decode,
616        )
617    }
618}
619
620pub struct ReverserEventStream {
621    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
622}
623
624impl std::marker::Unpin for ReverserEventStream {}
625
626impl futures::stream::FusedStream for ReverserEventStream {
627    fn is_terminated(&self) -> bool {
628        self.event_receiver.is_terminated()
629    }
630}
631
632impl futures::Stream for ReverserEventStream {
633    type Item = Result<ReverserEvent, fidl::Error>;
634
635    fn poll_next(
636        mut self: std::pin::Pin<&mut Self>,
637        cx: &mut std::task::Context<'_>,
638    ) -> std::task::Poll<Option<Self::Item>> {
639        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
640            &mut self.event_receiver,
641            cx
642        )?) {
643            Some(buf) => std::task::Poll::Ready(Some(ReverserEvent::decode(buf))),
644            None => std::task::Poll::Ready(None),
645        }
646    }
647}
648
649#[derive(Debug)]
650pub enum ReverserEvent {}
651
652impl ReverserEvent {
653    /// Decodes a message buffer as a [`ReverserEvent`].
654    fn decode(
655        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
656    ) -> Result<ReverserEvent, fidl::Error> {
657        let (bytes, _handles) = buf.split_mut();
658        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
659        debug_assert_eq!(tx_header.tx_id, 0);
660        match tx_header.ordinal {
661            _ => Err(fidl::Error::UnknownOrdinal {
662                ordinal: tx_header.ordinal,
663                protocol_name: <ReverserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
664            }),
665        }
666    }
667}
668
669/// A Stream of incoming requests for fuchsia.examples.inspect/Reverser.
670pub struct ReverserRequestStream {
671    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
672    is_terminated: bool,
673}
674
675impl std::marker::Unpin for ReverserRequestStream {}
676
677impl futures::stream::FusedStream for ReverserRequestStream {
678    fn is_terminated(&self) -> bool {
679        self.is_terminated
680    }
681}
682
683impl fidl::endpoints::RequestStream for ReverserRequestStream {
684    type Protocol = ReverserMarker;
685    type ControlHandle = ReverserControlHandle;
686
687    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
688        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
689    }
690
691    fn control_handle(&self) -> Self::ControlHandle {
692        ReverserControlHandle { inner: self.inner.clone() }
693    }
694
695    fn into_inner(
696        self,
697    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
698    {
699        (self.inner, self.is_terminated)
700    }
701
702    fn from_inner(
703        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
704        is_terminated: bool,
705    ) -> Self {
706        Self { inner, is_terminated }
707    }
708}
709
710impl futures::Stream for ReverserRequestStream {
711    type Item = Result<ReverserRequest, fidl::Error>;
712
713    fn poll_next(
714        mut self: std::pin::Pin<&mut Self>,
715        cx: &mut std::task::Context<'_>,
716    ) -> std::task::Poll<Option<Self::Item>> {
717        let this = &mut *self;
718        if this.inner.check_shutdown(cx) {
719            this.is_terminated = true;
720            return std::task::Poll::Ready(None);
721        }
722        if this.is_terminated {
723            panic!("polled ReverserRequestStream after completion");
724        }
725        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
726            |bytes, handles| {
727                match this.inner.channel().read_etc(cx, bytes, handles) {
728                    std::task::Poll::Ready(Ok(())) => {}
729                    std::task::Poll::Pending => return std::task::Poll::Pending,
730                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
731                        this.is_terminated = true;
732                        return std::task::Poll::Ready(None);
733                    }
734                    std::task::Poll::Ready(Err(e)) => {
735                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
736                            e.into(),
737                        ))))
738                    }
739                }
740
741                // A message has been received from the channel
742                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
743
744                std::task::Poll::Ready(Some(match header.ordinal {
745                    0x481eccb3af87ff3e => {
746                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
747                        let mut req = fidl::new_empty!(
748                            ReverserReverseRequest,
749                            fidl::encoding::DefaultFuchsiaResourceDialect
750                        );
751                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ReverserReverseRequest>(&header, _body_bytes, handles, &mut req)?;
752                        let control_handle = ReverserControlHandle { inner: this.inner.clone() };
753                        Ok(ReverserRequest::Reverse {
754                            input: req.input,
755
756                            responder: ReverserReverseResponder {
757                                control_handle: std::mem::ManuallyDrop::new(control_handle),
758                                tx_id: header.tx_id,
759                            },
760                        })
761                    }
762                    _ => Err(fidl::Error::UnknownOrdinal {
763                        ordinal: header.ordinal,
764                        protocol_name:
765                            <ReverserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
766                    }),
767                }))
768            },
769        )
770    }
771}
772
773#[derive(Debug)]
774pub enum ReverserRequest {
775    Reverse { input: String, responder: ReverserReverseResponder },
776}
777
778impl ReverserRequest {
779    #[allow(irrefutable_let_patterns)]
780    pub fn into_reverse(self) -> Option<(String, ReverserReverseResponder)> {
781        if let ReverserRequest::Reverse { input, responder } = self {
782            Some((input, responder))
783        } else {
784            None
785        }
786    }
787
788    /// Name of the method defined in FIDL
789    pub fn method_name(&self) -> &'static str {
790        match *self {
791            ReverserRequest::Reverse { .. } => "reverse",
792        }
793    }
794}
795
796#[derive(Debug, Clone)]
797pub struct ReverserControlHandle {
798    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
799}
800
801impl fidl::endpoints::ControlHandle for ReverserControlHandle {
802    fn shutdown(&self) {
803        self.inner.shutdown()
804    }
805    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
806        self.inner.shutdown_with_epitaph(status)
807    }
808
809    fn is_closed(&self) -> bool {
810        self.inner.channel().is_closed()
811    }
812    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
813        self.inner.channel().on_closed()
814    }
815
816    #[cfg(target_os = "fuchsia")]
817    fn signal_peer(
818        &self,
819        clear_mask: zx::Signals,
820        set_mask: zx::Signals,
821    ) -> Result<(), zx_status::Status> {
822        use fidl::Peered;
823        self.inner.channel().signal_peer(clear_mask, set_mask)
824    }
825}
826
827impl ReverserControlHandle {}
828
829#[must_use = "FIDL methods require a response to be sent"]
830#[derive(Debug)]
831pub struct ReverserReverseResponder {
832    control_handle: std::mem::ManuallyDrop<ReverserControlHandle>,
833    tx_id: u32,
834}
835
836/// Set the the channel to be shutdown (see [`ReverserControlHandle::shutdown`])
837/// if the responder is dropped without sending a response, so that the client
838/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
839impl std::ops::Drop for ReverserReverseResponder {
840    fn drop(&mut self) {
841        self.control_handle.shutdown();
842        // Safety: drops once, never accessed again
843        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
844    }
845}
846
847impl fidl::endpoints::Responder for ReverserReverseResponder {
848    type ControlHandle = ReverserControlHandle;
849
850    fn control_handle(&self) -> &ReverserControlHandle {
851        &self.control_handle
852    }
853
854    fn drop_without_shutdown(mut self) {
855        // Safety: drops once, never accessed again due to mem::forget
856        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
857        // Prevent Drop from running (which would shut down the channel)
858        std::mem::forget(self);
859    }
860}
861
862impl ReverserReverseResponder {
863    /// Sends a response to the FIDL transaction.
864    ///
865    /// Sets the channel to shutdown if an error occurs.
866    pub fn send(self, mut response: &str) -> Result<(), fidl::Error> {
867        let _result = self.send_raw(response);
868        if _result.is_err() {
869            self.control_handle.shutdown();
870        }
871        self.drop_without_shutdown();
872        _result
873    }
874
875    /// Similar to "send" but does not shutdown the channel if an error occurs.
876    pub fn send_no_shutdown_on_err(self, mut response: &str) -> Result<(), fidl::Error> {
877        let _result = self.send_raw(response);
878        self.drop_without_shutdown();
879        _result
880    }
881
882    fn send_raw(&self, mut response: &str) -> Result<(), fidl::Error> {
883        self.control_handle.inner.send::<ReverserReverseResponse>(
884            (response,),
885            self.tx_id,
886            0x481eccb3af87ff3e,
887            fidl::encoding::DynamicFlags::empty(),
888        )
889    }
890}
891
892mod internal {
893    use super::*;
894}