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