fidl_examples_canvas_baseline/
fidl_examples_canvas_baseline.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_examples_canvas_baseline_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.baseline.Instance";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for InstanceMarker {}
26
27pub trait InstanceProxyInterface: Send + Sync {
28    fn r#add_line(&self, line: &[Point; 2]) -> Result<(), fidl::Error>;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct InstanceSynchronousProxy {
33    client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for InstanceSynchronousProxy {
38    type Proxy = InstanceProxy;
39    type Protocol = InstanceMarker;
40
41    fn from_channel(inner: fidl::Channel) -> Self {
42        Self::new(inner)
43    }
44
45    fn into_channel(self) -> fidl::Channel {
46        self.client.into_channel()
47    }
48
49    fn as_channel(&self) -> &fidl::Channel {
50        self.client.as_channel()
51    }
52}
53
54#[cfg(target_os = "fuchsia")]
55impl InstanceSynchronousProxy {
56    pub fn new(channel: fidl::Channel) -> Self {
57        let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
58        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
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<InstanceEvent, fidl::Error> {
71        InstanceEvent::decode(self.client.wait_for_event(deadline)?)
72    }
73
74    /// Add a line to the canvas.
75    pub fn r#add_line(&self, mut line: &[Point; 2]) -> Result<(), fidl::Error> {
76        self.client.send::<InstanceAddLineRequest>(
77            (line,),
78            0x3f5b799d54b4aa0,
79            fidl::encoding::DynamicFlags::FLEXIBLE,
80        )
81    }
82}
83
84#[derive(Debug, Clone)]
85pub struct InstanceProxy {
86    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
87}
88
89impl fidl::endpoints::Proxy for InstanceProxy {
90    type Protocol = InstanceMarker;
91
92    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
93        Self::new(inner)
94    }
95
96    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
97        self.client.into_channel().map_err(|client| Self { client })
98    }
99
100    fn as_channel(&self) -> &::fidl::AsyncChannel {
101        self.client.as_channel()
102    }
103}
104
105impl InstanceProxy {
106    /// Create a new Proxy for examples.canvas.baseline/Instance.
107    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
108        let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
109        Self { client: fidl::client::Client::new(channel, protocol_name) }
110    }
111
112    /// Get a Stream of events from the remote end of the protocol.
113    ///
114    /// # Panics
115    ///
116    /// Panics if the event stream was already taken.
117    pub fn take_event_stream(&self) -> InstanceEventStream {
118        InstanceEventStream { event_receiver: self.client.take_event_receiver() }
119    }
120
121    /// Add a line to the canvas.
122    pub fn r#add_line(&self, mut line: &[Point; 2]) -> Result<(), fidl::Error> {
123        InstanceProxyInterface::r#add_line(self, line)
124    }
125}
126
127impl InstanceProxyInterface for InstanceProxy {
128    fn r#add_line(&self, mut line: &[Point; 2]) -> Result<(), fidl::Error> {
129        self.client.send::<InstanceAddLineRequest>(
130            (line,),
131            0x3f5b799d54b4aa0,
132            fidl::encoding::DynamicFlags::FLEXIBLE,
133        )
134    }
135}
136
137pub struct InstanceEventStream {
138    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
139}
140
141impl std::marker::Unpin for InstanceEventStream {}
142
143impl futures::stream::FusedStream for InstanceEventStream {
144    fn is_terminated(&self) -> bool {
145        self.event_receiver.is_terminated()
146    }
147}
148
149impl futures::Stream for InstanceEventStream {
150    type Item = Result<InstanceEvent, fidl::Error>;
151
152    fn poll_next(
153        mut self: std::pin::Pin<&mut Self>,
154        cx: &mut std::task::Context<'_>,
155    ) -> std::task::Poll<Option<Self::Item>> {
156        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
157            &mut self.event_receiver,
158            cx
159        )?) {
160            Some(buf) => std::task::Poll::Ready(Some(InstanceEvent::decode(buf))),
161            None => std::task::Poll::Ready(None),
162        }
163    }
164}
165
166#[derive(Debug)]
167pub enum InstanceEvent {
168    OnDrawn {
169        top_left: Point,
170        bottom_right: Point,
171    },
172    #[non_exhaustive]
173    _UnknownEvent {
174        /// Ordinal of the event that was sent.
175        ordinal: u64,
176    },
177}
178
179impl InstanceEvent {
180    #[allow(irrefutable_let_patterns)]
181    pub fn into_on_drawn(self) -> Option<(Point, Point)> {
182        if let InstanceEvent::OnDrawn { top_left, bottom_right } = self {
183            Some((top_left, bottom_right))
184        } else {
185            None
186        }
187    }
188
189    /// Decodes a message buffer as a [`InstanceEvent`].
190    fn decode(
191        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
192    ) -> Result<InstanceEvent, fidl::Error> {
193        let (bytes, _handles) = buf.split_mut();
194        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
195        debug_assert_eq!(tx_header.tx_id, 0);
196        match tx_header.ordinal {
197            0x2eeaa5f17200458d => {
198                let mut out =
199                    fidl::new_empty!(BoundingBox, fidl::encoding::DefaultFuchsiaResourceDialect);
200                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BoundingBox>(&tx_header, _body_bytes, _handles, &mut out)?;
201                Ok((InstanceEvent::OnDrawn {
202                    top_left: out.top_left,
203                    bottom_right: out.bottom_right,
204                }))
205            }
206            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
207                Ok(InstanceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
208            }
209            _ => Err(fidl::Error::UnknownOrdinal {
210                ordinal: tx_header.ordinal,
211                protocol_name: <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
212            }),
213        }
214    }
215}
216
217/// A Stream of incoming requests for examples.canvas.baseline/Instance.
218pub struct InstanceRequestStream {
219    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
220    is_terminated: bool,
221}
222
223impl std::marker::Unpin for InstanceRequestStream {}
224
225impl futures::stream::FusedStream for InstanceRequestStream {
226    fn is_terminated(&self) -> bool {
227        self.is_terminated
228    }
229}
230
231impl fidl::endpoints::RequestStream for InstanceRequestStream {
232    type Protocol = InstanceMarker;
233    type ControlHandle = InstanceControlHandle;
234
235    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
236        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
237    }
238
239    fn control_handle(&self) -> Self::ControlHandle {
240        InstanceControlHandle { inner: self.inner.clone() }
241    }
242
243    fn into_inner(
244        self,
245    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
246    {
247        (self.inner, self.is_terminated)
248    }
249
250    fn from_inner(
251        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
252        is_terminated: bool,
253    ) -> Self {
254        Self { inner, is_terminated }
255    }
256}
257
258impl futures::Stream for InstanceRequestStream {
259    type Item = Result<InstanceRequest, fidl::Error>;
260
261    fn poll_next(
262        mut self: std::pin::Pin<&mut Self>,
263        cx: &mut std::task::Context<'_>,
264    ) -> std::task::Poll<Option<Self::Item>> {
265        let this = &mut *self;
266        if this.inner.check_shutdown(cx) {
267            this.is_terminated = true;
268            return std::task::Poll::Ready(None);
269        }
270        if this.is_terminated {
271            panic!("polled InstanceRequestStream after completion");
272        }
273        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
274            |bytes, handles| {
275                match this.inner.channel().read_etc(cx, bytes, handles) {
276                    std::task::Poll::Ready(Ok(())) => {}
277                    std::task::Poll::Pending => return std::task::Poll::Pending,
278                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
279                        this.is_terminated = true;
280                        return std::task::Poll::Ready(None);
281                    }
282                    std::task::Poll::Ready(Err(e)) => {
283                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
284                            e.into(),
285                        ))))
286                    }
287                }
288
289                // A message has been received from the channel
290                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
291
292                std::task::Poll::Ready(Some(match header.ordinal {
293                    0x3f5b799d54b4aa0 => {
294                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
295                        let mut req = fidl::new_empty!(
296                            InstanceAddLineRequest,
297                            fidl::encoding::DefaultFuchsiaResourceDialect
298                        );
299                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InstanceAddLineRequest>(&header, _body_bytes, handles, &mut req)?;
300                        let control_handle = InstanceControlHandle { inner: this.inner.clone() };
301                        Ok(InstanceRequest::AddLine { line: req.line, control_handle })
302                    }
303                    _ if header.tx_id == 0
304                        && header
305                            .dynamic_flags()
306                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
307                    {
308                        Ok(InstanceRequest::_UnknownMethod {
309                            ordinal: header.ordinal,
310                            control_handle: InstanceControlHandle { inner: this.inner.clone() },
311                            method_type: fidl::MethodType::OneWay,
312                        })
313                    }
314                    _ if header
315                        .dynamic_flags()
316                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
317                    {
318                        this.inner.send_framework_err(
319                            fidl::encoding::FrameworkErr::UnknownMethod,
320                            header.tx_id,
321                            header.ordinal,
322                            header.dynamic_flags(),
323                            (bytes, handles),
324                        )?;
325                        Ok(InstanceRequest::_UnknownMethod {
326                            ordinal: header.ordinal,
327                            control_handle: InstanceControlHandle { inner: this.inner.clone() },
328                            method_type: fidl::MethodType::TwoWay,
329                        })
330                    }
331                    _ => Err(fidl::Error::UnknownOrdinal {
332                        ordinal: header.ordinal,
333                        protocol_name:
334                            <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
335                    }),
336                }))
337            },
338        )
339    }
340}
341
342/// Manages a single instance of a canvas. Each session of this protocol is responsible for a new
343/// canvas.
344#[derive(Debug)]
345pub enum InstanceRequest {
346    /// Add a line to the canvas.
347    AddLine { line: [Point; 2], control_handle: InstanceControlHandle },
348    /// An interaction was received which does not match any known method.
349    #[non_exhaustive]
350    _UnknownMethod {
351        /// Ordinal of the method that was called.
352        ordinal: u64,
353        control_handle: InstanceControlHandle,
354        method_type: fidl::MethodType,
355    },
356}
357
358impl InstanceRequest {
359    #[allow(irrefutable_let_patterns)]
360    pub fn into_add_line(self) -> Option<([Point; 2], InstanceControlHandle)> {
361        if let InstanceRequest::AddLine { line, control_handle } = self {
362            Some((line, control_handle))
363        } else {
364            None
365        }
366    }
367
368    /// Name of the method defined in FIDL
369    pub fn method_name(&self) -> &'static str {
370        match *self {
371            InstanceRequest::AddLine { .. } => "add_line",
372            InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
373                "unknown one-way method"
374            }
375            InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
376                "unknown two-way method"
377            }
378        }
379    }
380}
381
382#[derive(Debug, Clone)]
383pub struct InstanceControlHandle {
384    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
385}
386
387impl fidl::endpoints::ControlHandle for InstanceControlHandle {
388    fn shutdown(&self) {
389        self.inner.shutdown()
390    }
391    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
392        self.inner.shutdown_with_epitaph(status)
393    }
394
395    fn is_closed(&self) -> bool {
396        self.inner.channel().is_closed()
397    }
398    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
399        self.inner.channel().on_closed()
400    }
401
402    #[cfg(target_os = "fuchsia")]
403    fn signal_peer(
404        &self,
405        clear_mask: zx::Signals,
406        set_mask: zx::Signals,
407    ) -> Result<(), zx_status::Status> {
408        use fidl::Peered;
409        self.inner.channel().signal_peer(clear_mask, set_mask)
410    }
411}
412
413impl InstanceControlHandle {
414    pub fn send_on_drawn(
415        &self,
416        mut top_left: &Point,
417        mut bottom_right: &Point,
418    ) -> Result<(), fidl::Error> {
419        self.inner.send::<BoundingBox>(
420            (top_left, bottom_right),
421            0,
422            0x2eeaa5f17200458d,
423            fidl::encoding::DynamicFlags::FLEXIBLE,
424        )
425    }
426}
427
428mod internal {
429    use super::*;
430}