fidl_fuchsia_offers_test/
fidl_fuchsia_offers_test.rs

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