Skip to main content

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