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 fidl::endpoints::ControlHandle for FizzBuzzControlHandle {
364    fn shutdown(&self) {
365        self.inner.shutdown()
366    }
367
368    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
369        self.inner.shutdown_with_epitaph(status)
370    }
371
372    fn is_closed(&self) -> bool {
373        self.inner.channel().is_closed()
374    }
375    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
376        self.inner.channel().on_closed()
377    }
378
379    #[cfg(target_os = "fuchsia")]
380    fn signal_peer(
381        &self,
382        clear_mask: zx::Signals,
383        set_mask: zx::Signals,
384    ) -> Result<(), zx_status::Status> {
385        use fidl::Peered;
386        self.inner.channel().signal_peer(clear_mask, set_mask)
387    }
388}
389
390impl FizzBuzzControlHandle {}
391
392#[must_use = "FIDL methods require a response to be sent"]
393#[derive(Debug)]
394pub struct FizzBuzzExecuteResponder {
395    control_handle: std::mem::ManuallyDrop<FizzBuzzControlHandle>,
396    tx_id: u32,
397}
398
399/// Set the the channel to be shutdown (see [`FizzBuzzControlHandle::shutdown`])
400/// if the responder is dropped without sending a response, so that the client
401/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
402impl std::ops::Drop for FizzBuzzExecuteResponder {
403    fn drop(&mut self) {
404        self.control_handle.shutdown();
405        // Safety: drops once, never accessed again
406        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
407    }
408}
409
410impl fidl::endpoints::Responder for FizzBuzzExecuteResponder {
411    type ControlHandle = FizzBuzzControlHandle;
412
413    fn control_handle(&self) -> &FizzBuzzControlHandle {
414        &self.control_handle
415    }
416
417    fn drop_without_shutdown(mut self) {
418        // Safety: drops once, never accessed again due to mem::forget
419        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
420        // Prevent Drop from running (which would shut down the channel)
421        std::mem::forget(self);
422    }
423}
424
425impl FizzBuzzExecuteResponder {
426    /// Sends a response to the FIDL transaction.
427    ///
428    /// Sets the channel to shutdown if an error occurs.
429    pub fn send(self, mut response: &str) -> Result<(), fidl::Error> {
430        let _result = self.send_raw(response);
431        if _result.is_err() {
432            self.control_handle.shutdown();
433        }
434        self.drop_without_shutdown();
435        _result
436    }
437
438    /// Similar to "send" but does not shutdown the channel if an error occurs.
439    pub fn send_no_shutdown_on_err(self, mut response: &str) -> Result<(), fidl::Error> {
440        let _result = self.send_raw(response);
441        self.drop_without_shutdown();
442        _result
443    }
444
445    fn send_raw(&self, mut response: &str) -> Result<(), fidl::Error> {
446        self.control_handle.inner.send::<FizzBuzzExecuteResponse>(
447            (response,),
448            self.tx_id,
449            0x207cbeb002df3833,
450            fidl::encoding::DynamicFlags::empty(),
451        )
452    }
453}
454
455#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
456pub struct ReverserMarker;
457
458impl fidl::endpoints::ProtocolMarker for ReverserMarker {
459    type Proxy = ReverserProxy;
460    type RequestStream = ReverserRequestStream;
461    #[cfg(target_os = "fuchsia")]
462    type SynchronousProxy = ReverserSynchronousProxy;
463
464    const DEBUG_NAME: &'static str = "fuchsia.examples.inspect.Reverser";
465}
466impl fidl::endpoints::DiscoverableProtocolMarker for ReverserMarker {}
467
468pub trait ReverserProxyInterface: Send + Sync {
469    type ReverseResponseFut: std::future::Future<Output = Result<String, fidl::Error>> + Send;
470    fn r#reverse(&self, input: &str) -> Self::ReverseResponseFut;
471}
472#[derive(Debug)]
473#[cfg(target_os = "fuchsia")]
474pub struct ReverserSynchronousProxy {
475    client: fidl::client::sync::Client,
476}
477
478#[cfg(target_os = "fuchsia")]
479impl fidl::endpoints::SynchronousProxy for ReverserSynchronousProxy {
480    type Proxy = ReverserProxy;
481    type Protocol = ReverserMarker;
482
483    fn from_channel(inner: fidl::Channel) -> Self {
484        Self::new(inner)
485    }
486
487    fn into_channel(self) -> fidl::Channel {
488        self.client.into_channel()
489    }
490
491    fn as_channel(&self) -> &fidl::Channel {
492        self.client.as_channel()
493    }
494}
495
496#[cfg(target_os = "fuchsia")]
497impl ReverserSynchronousProxy {
498    pub fn new(channel: fidl::Channel) -> Self {
499        Self { client: fidl::client::sync::Client::new(channel) }
500    }
501
502    pub fn into_channel(self) -> fidl::Channel {
503        self.client.into_channel()
504    }
505
506    /// Waits until an event arrives and returns it. It is safe for other
507    /// threads to make concurrent requests while waiting for an event.
508    pub fn wait_for_event(
509        &self,
510        deadline: zx::MonotonicInstant,
511    ) -> Result<ReverserEvent, fidl::Error> {
512        ReverserEvent::decode(self.client.wait_for_event::<ReverserMarker>(deadline)?)
513    }
514
515    pub fn r#reverse(
516        &self,
517        mut input: &str,
518        ___deadline: zx::MonotonicInstant,
519    ) -> Result<String, fidl::Error> {
520        let _response = self
521            .client
522            .send_query::<ReverserReverseRequest, ReverserReverseResponse, ReverserMarker>(
523                (input,),
524                0x481eccb3af87ff3e,
525                fidl::encoding::DynamicFlags::empty(),
526                ___deadline,
527            )?;
528        Ok(_response.response)
529    }
530}
531
532#[cfg(target_os = "fuchsia")]
533impl From<ReverserSynchronousProxy> for zx::NullableHandle {
534    fn from(value: ReverserSynchronousProxy) -> Self {
535        value.into_channel().into()
536    }
537}
538
539#[cfg(target_os = "fuchsia")]
540impl From<fidl::Channel> for ReverserSynchronousProxy {
541    fn from(value: fidl::Channel) -> Self {
542        Self::new(value)
543    }
544}
545
546#[cfg(target_os = "fuchsia")]
547impl fidl::endpoints::FromClient for ReverserSynchronousProxy {
548    type Protocol = ReverserMarker;
549
550    fn from_client(value: fidl::endpoints::ClientEnd<ReverserMarker>) -> Self {
551        Self::new(value.into_channel())
552    }
553}
554
555#[derive(Debug, Clone)]
556pub struct ReverserProxy {
557    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
558}
559
560impl fidl::endpoints::Proxy for ReverserProxy {
561    type Protocol = ReverserMarker;
562
563    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
564        Self::new(inner)
565    }
566
567    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
568        self.client.into_channel().map_err(|client| Self { client })
569    }
570
571    fn as_channel(&self) -> &::fidl::AsyncChannel {
572        self.client.as_channel()
573    }
574}
575
576impl ReverserProxy {
577    /// Create a new Proxy for fuchsia.examples.inspect/Reverser.
578    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
579        let protocol_name = <ReverserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
580        Self { client: fidl::client::Client::new(channel, protocol_name) }
581    }
582
583    /// Get a Stream of events from the remote end of the protocol.
584    ///
585    /// # Panics
586    ///
587    /// Panics if the event stream was already taken.
588    pub fn take_event_stream(&self) -> ReverserEventStream {
589        ReverserEventStream { event_receiver: self.client.take_event_receiver() }
590    }
591
592    pub fn r#reverse(
593        &self,
594        mut input: &str,
595    ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
596        ReverserProxyInterface::r#reverse(self, input)
597    }
598}
599
600impl ReverserProxyInterface for ReverserProxy {
601    type ReverseResponseFut =
602        fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
603    fn r#reverse(&self, mut input: &str) -> Self::ReverseResponseFut {
604        fn _decode(
605            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
606        ) -> Result<String, fidl::Error> {
607            let _response = fidl::client::decode_transaction_body::<
608                ReverserReverseResponse,
609                fidl::encoding::DefaultFuchsiaResourceDialect,
610                0x481eccb3af87ff3e,
611            >(_buf?)?;
612            Ok(_response.response)
613        }
614        self.client.send_query_and_decode::<ReverserReverseRequest, String>(
615            (input,),
616            0x481eccb3af87ff3e,
617            fidl::encoding::DynamicFlags::empty(),
618            _decode,
619        )
620    }
621}
622
623pub struct ReverserEventStream {
624    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
625}
626
627impl std::marker::Unpin for ReverserEventStream {}
628
629impl futures::stream::FusedStream for ReverserEventStream {
630    fn is_terminated(&self) -> bool {
631        self.event_receiver.is_terminated()
632    }
633}
634
635impl futures::Stream for ReverserEventStream {
636    type Item = Result<ReverserEvent, fidl::Error>;
637
638    fn poll_next(
639        mut self: std::pin::Pin<&mut Self>,
640        cx: &mut std::task::Context<'_>,
641    ) -> std::task::Poll<Option<Self::Item>> {
642        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
643            &mut self.event_receiver,
644            cx
645        )?) {
646            Some(buf) => std::task::Poll::Ready(Some(ReverserEvent::decode(buf))),
647            None => std::task::Poll::Ready(None),
648        }
649    }
650}
651
652#[derive(Debug)]
653pub enum ReverserEvent {}
654
655impl ReverserEvent {
656    /// Decodes a message buffer as a [`ReverserEvent`].
657    fn decode(
658        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
659    ) -> Result<ReverserEvent, fidl::Error> {
660        let (bytes, _handles) = buf.split_mut();
661        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
662        debug_assert_eq!(tx_header.tx_id, 0);
663        match tx_header.ordinal {
664            _ => Err(fidl::Error::UnknownOrdinal {
665                ordinal: tx_header.ordinal,
666                protocol_name: <ReverserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
667            }),
668        }
669    }
670}
671
672/// A Stream of incoming requests for fuchsia.examples.inspect/Reverser.
673pub struct ReverserRequestStream {
674    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
675    is_terminated: bool,
676}
677
678impl std::marker::Unpin for ReverserRequestStream {}
679
680impl futures::stream::FusedStream for ReverserRequestStream {
681    fn is_terminated(&self) -> bool {
682        self.is_terminated
683    }
684}
685
686impl fidl::endpoints::RequestStream for ReverserRequestStream {
687    type Protocol = ReverserMarker;
688    type ControlHandle = ReverserControlHandle;
689
690    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
691        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
692    }
693
694    fn control_handle(&self) -> Self::ControlHandle {
695        ReverserControlHandle { inner: self.inner.clone() }
696    }
697
698    fn into_inner(
699        self,
700    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
701    {
702        (self.inner, self.is_terminated)
703    }
704
705    fn from_inner(
706        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
707        is_terminated: bool,
708    ) -> Self {
709        Self { inner, is_terminated }
710    }
711}
712
713impl futures::Stream for ReverserRequestStream {
714    type Item = Result<ReverserRequest, fidl::Error>;
715
716    fn poll_next(
717        mut self: std::pin::Pin<&mut Self>,
718        cx: &mut std::task::Context<'_>,
719    ) -> std::task::Poll<Option<Self::Item>> {
720        let this = &mut *self;
721        if this.inner.check_shutdown(cx) {
722            this.is_terminated = true;
723            return std::task::Poll::Ready(None);
724        }
725        if this.is_terminated {
726            panic!("polled ReverserRequestStream after completion");
727        }
728        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
729            |bytes, handles| {
730                match this.inner.channel().read_etc(cx, bytes, handles) {
731                    std::task::Poll::Ready(Ok(())) => {}
732                    std::task::Poll::Pending => return std::task::Poll::Pending,
733                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
734                        this.is_terminated = true;
735                        return std::task::Poll::Ready(None);
736                    }
737                    std::task::Poll::Ready(Err(e)) => {
738                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
739                            e.into(),
740                        ))));
741                    }
742                }
743
744                // A message has been received from the channel
745                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
746
747                std::task::Poll::Ready(Some(match header.ordinal {
748                    0x481eccb3af87ff3e => {
749                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
750                        let mut req = fidl::new_empty!(
751                            ReverserReverseRequest,
752                            fidl::encoding::DefaultFuchsiaResourceDialect
753                        );
754                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ReverserReverseRequest>(&header, _body_bytes, handles, &mut req)?;
755                        let control_handle = ReverserControlHandle { inner: this.inner.clone() };
756                        Ok(ReverserRequest::Reverse {
757                            input: req.input,
758
759                            responder: ReverserReverseResponder {
760                                control_handle: std::mem::ManuallyDrop::new(control_handle),
761                                tx_id: header.tx_id,
762                            },
763                        })
764                    }
765                    _ => Err(fidl::Error::UnknownOrdinal {
766                        ordinal: header.ordinal,
767                        protocol_name:
768                            <ReverserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
769                    }),
770                }))
771            },
772        )
773    }
774}
775
776#[derive(Debug)]
777pub enum ReverserRequest {
778    Reverse { input: String, responder: ReverserReverseResponder },
779}
780
781impl ReverserRequest {
782    #[allow(irrefutable_let_patterns)]
783    pub fn into_reverse(self) -> Option<(String, ReverserReverseResponder)> {
784        if let ReverserRequest::Reverse { input, responder } = self {
785            Some((input, responder))
786        } else {
787            None
788        }
789    }
790
791    /// Name of the method defined in FIDL
792    pub fn method_name(&self) -> &'static str {
793        match *self {
794            ReverserRequest::Reverse { .. } => "reverse",
795        }
796    }
797}
798
799#[derive(Debug, Clone)]
800pub struct ReverserControlHandle {
801    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
802}
803
804impl fidl::endpoints::ControlHandle for ReverserControlHandle {
805    fn shutdown(&self) {
806        self.inner.shutdown()
807    }
808
809    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
810        self.inner.shutdown_with_epitaph(status)
811    }
812
813    fn is_closed(&self) -> bool {
814        self.inner.channel().is_closed()
815    }
816    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
817        self.inner.channel().on_closed()
818    }
819
820    #[cfg(target_os = "fuchsia")]
821    fn signal_peer(
822        &self,
823        clear_mask: zx::Signals,
824        set_mask: zx::Signals,
825    ) -> Result<(), zx_status::Status> {
826        use fidl::Peered;
827        self.inner.channel().signal_peer(clear_mask, set_mask)
828    }
829}
830
831impl ReverserControlHandle {}
832
833#[must_use = "FIDL methods require a response to be sent"]
834#[derive(Debug)]
835pub struct ReverserReverseResponder {
836    control_handle: std::mem::ManuallyDrop<ReverserControlHandle>,
837    tx_id: u32,
838}
839
840/// Set the the channel to be shutdown (see [`ReverserControlHandle::shutdown`])
841/// if the responder is dropped without sending a response, so that the client
842/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
843impl std::ops::Drop for ReverserReverseResponder {
844    fn drop(&mut self) {
845        self.control_handle.shutdown();
846        // Safety: drops once, never accessed again
847        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
848    }
849}
850
851impl fidl::endpoints::Responder for ReverserReverseResponder {
852    type ControlHandle = ReverserControlHandle;
853
854    fn control_handle(&self) -> &ReverserControlHandle {
855        &self.control_handle
856    }
857
858    fn drop_without_shutdown(mut self) {
859        // Safety: drops once, never accessed again due to mem::forget
860        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
861        // Prevent Drop from running (which would shut down the channel)
862        std::mem::forget(self);
863    }
864}
865
866impl ReverserReverseResponder {
867    /// Sends a response to the FIDL transaction.
868    ///
869    /// Sets the channel to shutdown if an error occurs.
870    pub fn send(self, mut response: &str) -> Result<(), fidl::Error> {
871        let _result = self.send_raw(response);
872        if _result.is_err() {
873            self.control_handle.shutdown();
874        }
875        self.drop_without_shutdown();
876        _result
877    }
878
879    /// Similar to "send" but does not shutdown the channel if an error occurs.
880    pub fn send_no_shutdown_on_err(self, mut response: &str) -> Result<(), fidl::Error> {
881        let _result = self.send_raw(response);
882        self.drop_without_shutdown();
883        _result
884    }
885
886    fn send_raw(&self, mut response: &str) -> Result<(), fidl::Error> {
887        self.control_handle.inner.send::<ReverserReverseResponse>(
888            (response,),
889            self.tx_id,
890            0x481eccb3af87ff3e,
891            fidl::encoding::DynamicFlags::empty(),
892        )
893    }
894}
895
896mod internal {
897    use super::*;
898}