Skip to main content

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