1#![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_examples_canvas_clientrequesteddraw__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct InstanceMarker;
16
17impl fidl::endpoints::ProtocolMarker for InstanceMarker {
18    type Proxy = InstanceProxy;
19    type RequestStream = InstanceRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = InstanceSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "examples.canvas.clientrequesteddraw.Instance";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for InstanceMarker {}
26
27pub trait InstanceProxyInterface: Send + Sync {
28    fn r#add_lines(&self, lines: &[[Point; 2]]) -> Result<(), fidl::Error>;
29    type ReadyResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
30    fn r#ready(&self) -> Self::ReadyResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct InstanceSynchronousProxy {
35    client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for InstanceSynchronousProxy {
40    type Proxy = InstanceProxy;
41    type Protocol = InstanceMarker;
42
43    fn from_channel(inner: fidl::Channel) -> Self {
44        Self::new(inner)
45    }
46
47    fn into_channel(self) -> fidl::Channel {
48        self.client.into_channel()
49    }
50
51    fn as_channel(&self) -> &fidl::Channel {
52        self.client.as_channel()
53    }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl InstanceSynchronousProxy {
58    pub fn new(channel: fidl::Channel) -> Self {
59        let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
60        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
61    }
62
63    pub fn into_channel(self) -> fidl::Channel {
64        self.client.into_channel()
65    }
66
67    pub fn wait_for_event(
70        &self,
71        deadline: zx::MonotonicInstant,
72    ) -> Result<InstanceEvent, fidl::Error> {
73        InstanceEvent::decode(self.client.wait_for_event(deadline)?)
74    }
75
76    pub fn r#add_lines(&self, mut lines: &[[Point; 2]]) -> Result<(), fidl::Error> {
80        self.client.send::<InstanceAddLinesRequest>(
81            (lines,),
82            0x5a82f0b30f970bd6,
83            fidl::encoding::DynamicFlags::FLEXIBLE,
84        )
85    }
86
87    pub fn r#ready(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
98        let _response = self.client.send_query::<
99            fidl::encoding::EmptyPayload,
100            fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
101        >(
102            (),
103            0x3458d7a668873150,
104            fidl::encoding::DynamicFlags::FLEXIBLE,
105            ___deadline,
106        )?
107        .into_result::<InstanceMarker>("ready")?;
108        Ok(_response)
109    }
110}
111
112#[cfg(target_os = "fuchsia")]
113impl From<InstanceSynchronousProxy> for zx::Handle {
114    fn from(value: InstanceSynchronousProxy) -> Self {
115        value.into_channel().into()
116    }
117}
118
119#[cfg(target_os = "fuchsia")]
120impl From<fidl::Channel> for InstanceSynchronousProxy {
121    fn from(value: fidl::Channel) -> Self {
122        Self::new(value)
123    }
124}
125
126#[cfg(target_os = "fuchsia")]
127impl fidl::endpoints::FromClient for InstanceSynchronousProxy {
128    type Protocol = InstanceMarker;
129
130    fn from_client(value: fidl::endpoints::ClientEnd<InstanceMarker>) -> Self {
131        Self::new(value.into_channel())
132    }
133}
134
135#[derive(Debug, Clone)]
136pub struct InstanceProxy {
137    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
138}
139
140impl fidl::endpoints::Proxy for InstanceProxy {
141    type Protocol = InstanceMarker;
142
143    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
144        Self::new(inner)
145    }
146
147    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
148        self.client.into_channel().map_err(|client| Self { client })
149    }
150
151    fn as_channel(&self) -> &::fidl::AsyncChannel {
152        self.client.as_channel()
153    }
154}
155
156impl InstanceProxy {
157    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
159        let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
160        Self { client: fidl::client::Client::new(channel, protocol_name) }
161    }
162
163    pub fn take_event_stream(&self) -> InstanceEventStream {
169        InstanceEventStream { event_receiver: self.client.take_event_receiver() }
170    }
171
172    pub fn r#add_lines(&self, mut lines: &[[Point; 2]]) -> Result<(), fidl::Error> {
176        InstanceProxyInterface::r#add_lines(self, lines)
177    }
178
179    pub fn r#ready(
190        &self,
191    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
192        InstanceProxyInterface::r#ready(self)
193    }
194}
195
196impl InstanceProxyInterface for InstanceProxy {
197    fn r#add_lines(&self, mut lines: &[[Point; 2]]) -> Result<(), fidl::Error> {
198        self.client.send::<InstanceAddLinesRequest>(
199            (lines,),
200            0x5a82f0b30f970bd6,
201            fidl::encoding::DynamicFlags::FLEXIBLE,
202        )
203    }
204
205    type ReadyResponseFut =
206        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
207    fn r#ready(&self) -> Self::ReadyResponseFut {
208        fn _decode(
209            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
210        ) -> Result<(), fidl::Error> {
211            let _response = fidl::client::decode_transaction_body::<
212                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
213                fidl::encoding::DefaultFuchsiaResourceDialect,
214                0x3458d7a668873150,
215            >(_buf?)?
216            .into_result::<InstanceMarker>("ready")?;
217            Ok(_response)
218        }
219        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
220            (),
221            0x3458d7a668873150,
222            fidl::encoding::DynamicFlags::FLEXIBLE,
223            _decode,
224        )
225    }
226}
227
228pub struct InstanceEventStream {
229    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
230}
231
232impl std::marker::Unpin for InstanceEventStream {}
233
234impl futures::stream::FusedStream for InstanceEventStream {
235    fn is_terminated(&self) -> bool {
236        self.event_receiver.is_terminated()
237    }
238}
239
240impl futures::Stream for InstanceEventStream {
241    type Item = Result<InstanceEvent, fidl::Error>;
242
243    fn poll_next(
244        mut self: std::pin::Pin<&mut Self>,
245        cx: &mut std::task::Context<'_>,
246    ) -> std::task::Poll<Option<Self::Item>> {
247        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
248            &mut self.event_receiver,
249            cx
250        )?) {
251            Some(buf) => std::task::Poll::Ready(Some(InstanceEvent::decode(buf))),
252            None => std::task::Poll::Ready(None),
253        }
254    }
255}
256
257#[derive(Debug)]
258pub enum InstanceEvent {
259    OnDrawn {
260        top_left: Point,
261        bottom_right: Point,
262    },
263    #[non_exhaustive]
264    _UnknownEvent {
265        ordinal: u64,
267    },
268}
269
270impl InstanceEvent {
271    #[allow(irrefutable_let_patterns)]
272    pub fn into_on_drawn(self) -> Option<(Point, Point)> {
273        if let InstanceEvent::OnDrawn { top_left, bottom_right } = self {
274            Some((top_left, bottom_right))
275        } else {
276            None
277        }
278    }
279
280    fn decode(
282        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
283    ) -> Result<InstanceEvent, fidl::Error> {
284        let (bytes, _handles) = buf.split_mut();
285        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
286        debug_assert_eq!(tx_header.tx_id, 0);
287        match tx_header.ordinal {
288            0x25e6d8494623419a => {
289                let mut out =
290                    fidl::new_empty!(BoundingBox, fidl::encoding::DefaultFuchsiaResourceDialect);
291                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BoundingBox>(&tx_header, _body_bytes, _handles, &mut out)?;
292                Ok((InstanceEvent::OnDrawn {
293                    top_left: out.top_left,
294                    bottom_right: out.bottom_right,
295                }))
296            }
297            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
298                Ok(InstanceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
299            }
300            _ => Err(fidl::Error::UnknownOrdinal {
301                ordinal: tx_header.ordinal,
302                protocol_name: <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
303            }),
304        }
305    }
306}
307
308pub struct InstanceRequestStream {
310    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
311    is_terminated: bool,
312}
313
314impl std::marker::Unpin for InstanceRequestStream {}
315
316impl futures::stream::FusedStream for InstanceRequestStream {
317    fn is_terminated(&self) -> bool {
318        self.is_terminated
319    }
320}
321
322impl fidl::endpoints::RequestStream for InstanceRequestStream {
323    type Protocol = InstanceMarker;
324    type ControlHandle = InstanceControlHandle;
325
326    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
327        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
328    }
329
330    fn control_handle(&self) -> Self::ControlHandle {
331        InstanceControlHandle { inner: self.inner.clone() }
332    }
333
334    fn into_inner(
335        self,
336    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
337    {
338        (self.inner, self.is_terminated)
339    }
340
341    fn from_inner(
342        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
343        is_terminated: bool,
344    ) -> Self {
345        Self { inner, is_terminated }
346    }
347}
348
349impl futures::Stream for InstanceRequestStream {
350    type Item = Result<InstanceRequest, fidl::Error>;
351
352    fn poll_next(
353        mut self: std::pin::Pin<&mut Self>,
354        cx: &mut std::task::Context<'_>,
355    ) -> std::task::Poll<Option<Self::Item>> {
356        let this = &mut *self;
357        if this.inner.check_shutdown(cx) {
358            this.is_terminated = true;
359            return std::task::Poll::Ready(None);
360        }
361        if this.is_terminated {
362            panic!("polled InstanceRequestStream after completion");
363        }
364        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
365            |bytes, handles| {
366                match this.inner.channel().read_etc(cx, bytes, handles) {
367                    std::task::Poll::Ready(Ok(())) => {}
368                    std::task::Poll::Pending => return std::task::Poll::Pending,
369                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
370                        this.is_terminated = true;
371                        return std::task::Poll::Ready(None);
372                    }
373                    std::task::Poll::Ready(Err(e)) => {
374                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
375                            e.into(),
376                        ))));
377                    }
378                }
379
380                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
382
383                std::task::Poll::Ready(Some(match header.ordinal {
384                    0x5a82f0b30f970bd6 => {
385                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
386                        let mut req = fidl::new_empty!(
387                            InstanceAddLinesRequest,
388                            fidl::encoding::DefaultFuchsiaResourceDialect
389                        );
390                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InstanceAddLinesRequest>(&header, _body_bytes, handles, &mut req)?;
391                        let control_handle = InstanceControlHandle { inner: this.inner.clone() };
392                        Ok(InstanceRequest::AddLines { lines: req.lines, control_handle })
393                    }
394                    0x3458d7a668873150 => {
395                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
396                        let mut req = fidl::new_empty!(
397                            fidl::encoding::EmptyPayload,
398                            fidl::encoding::DefaultFuchsiaResourceDialect
399                        );
400                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
401                        let control_handle = InstanceControlHandle { inner: this.inner.clone() };
402                        Ok(InstanceRequest::Ready {
403                            responder: InstanceReadyResponder {
404                                control_handle: std::mem::ManuallyDrop::new(control_handle),
405                                tx_id: header.tx_id,
406                            },
407                        })
408                    }
409                    _ if header.tx_id == 0
410                        && header
411                            .dynamic_flags()
412                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
413                    {
414                        Ok(InstanceRequest::_UnknownMethod {
415                            ordinal: header.ordinal,
416                            control_handle: InstanceControlHandle { inner: this.inner.clone() },
417                            method_type: fidl::MethodType::OneWay,
418                        })
419                    }
420                    _ if header
421                        .dynamic_flags()
422                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
423                    {
424                        this.inner.send_framework_err(
425                            fidl::encoding::FrameworkErr::UnknownMethod,
426                            header.tx_id,
427                            header.ordinal,
428                            header.dynamic_flags(),
429                            (bytes, handles),
430                        )?;
431                        Ok(InstanceRequest::_UnknownMethod {
432                            ordinal: header.ordinal,
433                            control_handle: InstanceControlHandle { inner: this.inner.clone() },
434                            method_type: fidl::MethodType::TwoWay,
435                        })
436                    }
437                    _ => Err(fidl::Error::UnknownOrdinal {
438                        ordinal: header.ordinal,
439                        protocol_name:
440                            <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
441                    }),
442                }))
443            },
444        )
445    }
446}
447
448#[derive(Debug)]
451pub enum InstanceRequest {
452    AddLines { lines: Vec<[Point; 2]>, control_handle: InstanceControlHandle },
456    Ready { responder: InstanceReadyResponder },
467    #[non_exhaustive]
469    _UnknownMethod {
470        ordinal: u64,
472        control_handle: InstanceControlHandle,
473        method_type: fidl::MethodType,
474    },
475}
476
477impl InstanceRequest {
478    #[allow(irrefutable_let_patterns)]
479    pub fn into_add_lines(self) -> Option<(Vec<[Point; 2]>, InstanceControlHandle)> {
480        if let InstanceRequest::AddLines { lines, control_handle } = self {
481            Some((lines, control_handle))
482        } else {
483            None
484        }
485    }
486
487    #[allow(irrefutable_let_patterns)]
488    pub fn into_ready(self) -> Option<(InstanceReadyResponder)> {
489        if let InstanceRequest::Ready { responder } = self { Some((responder)) } else { None }
490    }
491
492    pub fn method_name(&self) -> &'static str {
494        match *self {
495            InstanceRequest::AddLines { .. } => "add_lines",
496            InstanceRequest::Ready { .. } => "ready",
497            InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
498                "unknown one-way method"
499            }
500            InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
501                "unknown two-way method"
502            }
503        }
504    }
505}
506
507#[derive(Debug, Clone)]
508pub struct InstanceControlHandle {
509    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
510}
511
512impl fidl::endpoints::ControlHandle for InstanceControlHandle {
513    fn shutdown(&self) {
514        self.inner.shutdown()
515    }
516    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
517        self.inner.shutdown_with_epitaph(status)
518    }
519
520    fn is_closed(&self) -> bool {
521        self.inner.channel().is_closed()
522    }
523    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
524        self.inner.channel().on_closed()
525    }
526
527    #[cfg(target_os = "fuchsia")]
528    fn signal_peer(
529        &self,
530        clear_mask: zx::Signals,
531        set_mask: zx::Signals,
532    ) -> Result<(), zx_status::Status> {
533        use fidl::Peered;
534        self.inner.channel().signal_peer(clear_mask, set_mask)
535    }
536}
537
538impl InstanceControlHandle {
539    pub fn send_on_drawn(
540        &self,
541        mut top_left: &Point,
542        mut bottom_right: &Point,
543    ) -> Result<(), fidl::Error> {
544        self.inner.send::<BoundingBox>(
545            (top_left, bottom_right),
546            0,
547            0x25e6d8494623419a,
548            fidl::encoding::DynamicFlags::FLEXIBLE,
549        )
550    }
551}
552
553#[must_use = "FIDL methods require a response to be sent"]
554#[derive(Debug)]
555pub struct InstanceReadyResponder {
556    control_handle: std::mem::ManuallyDrop<InstanceControlHandle>,
557    tx_id: u32,
558}
559
560impl std::ops::Drop for InstanceReadyResponder {
564    fn drop(&mut self) {
565        self.control_handle.shutdown();
566        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
568    }
569}
570
571impl fidl::endpoints::Responder for InstanceReadyResponder {
572    type ControlHandle = InstanceControlHandle;
573
574    fn control_handle(&self) -> &InstanceControlHandle {
575        &self.control_handle
576    }
577
578    fn drop_without_shutdown(mut self) {
579        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
581        std::mem::forget(self);
583    }
584}
585
586impl InstanceReadyResponder {
587    pub fn send(self) -> Result<(), fidl::Error> {
591        let _result = self.send_raw();
592        if _result.is_err() {
593            self.control_handle.shutdown();
594        }
595        self.drop_without_shutdown();
596        _result
597    }
598
599    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
601        let _result = self.send_raw();
602        self.drop_without_shutdown();
603        _result
604    }
605
606    fn send_raw(&self) -> Result<(), fidl::Error> {
607        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
608            fidl::encoding::Flexible::new(()),
609            self.tx_id,
610            0x3458d7a668873150,
611            fidl::encoding::DynamicFlags::FLEXIBLE,
612        )
613    }
614}
615
616mod internal {
617    use super::*;
618}