fidl_examples_canvas_baseline/
fidl_examples_canvas_baseline.rs1#![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 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 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#[cfg(target_os = "fuchsia")]
85impl From<InstanceSynchronousProxy> for zx::Handle {
86 fn from(value: InstanceSynchronousProxy) -> Self {
87 value.into_channel().into()
88 }
89}
90
91#[cfg(target_os = "fuchsia")]
92impl From<fidl::Channel> for InstanceSynchronousProxy {
93 fn from(value: fidl::Channel) -> Self {
94 Self::new(value)
95 }
96}
97
98#[cfg(target_os = "fuchsia")]
99impl fidl::endpoints::FromClient for InstanceSynchronousProxy {
100 type Protocol = InstanceMarker;
101
102 fn from_client(value: fidl::endpoints::ClientEnd<InstanceMarker>) -> Self {
103 Self::new(value.into_channel())
104 }
105}
106
107#[derive(Debug, Clone)]
108pub struct InstanceProxy {
109 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
110}
111
112impl fidl::endpoints::Proxy for InstanceProxy {
113 type Protocol = InstanceMarker;
114
115 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
116 Self::new(inner)
117 }
118
119 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
120 self.client.into_channel().map_err(|client| Self { client })
121 }
122
123 fn as_channel(&self) -> &::fidl::AsyncChannel {
124 self.client.as_channel()
125 }
126}
127
128impl InstanceProxy {
129 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
131 let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
132 Self { client: fidl::client::Client::new(channel, protocol_name) }
133 }
134
135 pub fn take_event_stream(&self) -> InstanceEventStream {
141 InstanceEventStream { event_receiver: self.client.take_event_receiver() }
142 }
143
144 pub fn r#add_line(&self, mut line: &[Point; 2]) -> Result<(), fidl::Error> {
146 InstanceProxyInterface::r#add_line(self, line)
147 }
148}
149
150impl InstanceProxyInterface for InstanceProxy {
151 fn r#add_line(&self, mut line: &[Point; 2]) -> Result<(), fidl::Error> {
152 self.client.send::<InstanceAddLineRequest>(
153 (line,),
154 0x3f5b799d54b4aa0,
155 fidl::encoding::DynamicFlags::FLEXIBLE,
156 )
157 }
158}
159
160pub struct InstanceEventStream {
161 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
162}
163
164impl std::marker::Unpin for InstanceEventStream {}
165
166impl futures::stream::FusedStream for InstanceEventStream {
167 fn is_terminated(&self) -> bool {
168 self.event_receiver.is_terminated()
169 }
170}
171
172impl futures::Stream for InstanceEventStream {
173 type Item = Result<InstanceEvent, fidl::Error>;
174
175 fn poll_next(
176 mut self: std::pin::Pin<&mut Self>,
177 cx: &mut std::task::Context<'_>,
178 ) -> std::task::Poll<Option<Self::Item>> {
179 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
180 &mut self.event_receiver,
181 cx
182 )?) {
183 Some(buf) => std::task::Poll::Ready(Some(InstanceEvent::decode(buf))),
184 None => std::task::Poll::Ready(None),
185 }
186 }
187}
188
189#[derive(Debug)]
190pub enum InstanceEvent {
191 OnDrawn {
192 top_left: Point,
193 bottom_right: Point,
194 },
195 #[non_exhaustive]
196 _UnknownEvent {
197 ordinal: u64,
199 },
200}
201
202impl InstanceEvent {
203 #[allow(irrefutable_let_patterns)]
204 pub fn into_on_drawn(self) -> Option<(Point, Point)> {
205 if let InstanceEvent::OnDrawn { top_left, bottom_right } = self {
206 Some((top_left, bottom_right))
207 } else {
208 None
209 }
210 }
211
212 fn decode(
214 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
215 ) -> Result<InstanceEvent, fidl::Error> {
216 let (bytes, _handles) = buf.split_mut();
217 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
218 debug_assert_eq!(tx_header.tx_id, 0);
219 match tx_header.ordinal {
220 0x2eeaa5f17200458d => {
221 let mut out =
222 fidl::new_empty!(BoundingBox, fidl::encoding::DefaultFuchsiaResourceDialect);
223 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BoundingBox>(&tx_header, _body_bytes, _handles, &mut out)?;
224 Ok((InstanceEvent::OnDrawn {
225 top_left: out.top_left,
226 bottom_right: out.bottom_right,
227 }))
228 }
229 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
230 Ok(InstanceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
231 }
232 _ => Err(fidl::Error::UnknownOrdinal {
233 ordinal: tx_header.ordinal,
234 protocol_name: <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
235 }),
236 }
237 }
238}
239
240pub struct InstanceRequestStream {
242 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
243 is_terminated: bool,
244}
245
246impl std::marker::Unpin for InstanceRequestStream {}
247
248impl futures::stream::FusedStream for InstanceRequestStream {
249 fn is_terminated(&self) -> bool {
250 self.is_terminated
251 }
252}
253
254impl fidl::endpoints::RequestStream for InstanceRequestStream {
255 type Protocol = InstanceMarker;
256 type ControlHandle = InstanceControlHandle;
257
258 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
259 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
260 }
261
262 fn control_handle(&self) -> Self::ControlHandle {
263 InstanceControlHandle { inner: self.inner.clone() }
264 }
265
266 fn into_inner(
267 self,
268 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
269 {
270 (self.inner, self.is_terminated)
271 }
272
273 fn from_inner(
274 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
275 is_terminated: bool,
276 ) -> Self {
277 Self { inner, is_terminated }
278 }
279}
280
281impl futures::Stream for InstanceRequestStream {
282 type Item = Result<InstanceRequest, fidl::Error>;
283
284 fn poll_next(
285 mut self: std::pin::Pin<&mut Self>,
286 cx: &mut std::task::Context<'_>,
287 ) -> std::task::Poll<Option<Self::Item>> {
288 let this = &mut *self;
289 if this.inner.check_shutdown(cx) {
290 this.is_terminated = true;
291 return std::task::Poll::Ready(None);
292 }
293 if this.is_terminated {
294 panic!("polled InstanceRequestStream after completion");
295 }
296 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
297 |bytes, handles| {
298 match this.inner.channel().read_etc(cx, bytes, handles) {
299 std::task::Poll::Ready(Ok(())) => {}
300 std::task::Poll::Pending => return std::task::Poll::Pending,
301 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
302 this.is_terminated = true;
303 return std::task::Poll::Ready(None);
304 }
305 std::task::Poll::Ready(Err(e)) => {
306 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
307 e.into(),
308 ))))
309 }
310 }
311
312 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
314
315 std::task::Poll::Ready(Some(match header.ordinal {
316 0x3f5b799d54b4aa0 => {
317 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
318 let mut req = fidl::new_empty!(
319 InstanceAddLineRequest,
320 fidl::encoding::DefaultFuchsiaResourceDialect
321 );
322 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InstanceAddLineRequest>(&header, _body_bytes, handles, &mut req)?;
323 let control_handle = InstanceControlHandle { inner: this.inner.clone() };
324 Ok(InstanceRequest::AddLine { line: req.line, control_handle })
325 }
326 _ if header.tx_id == 0
327 && header
328 .dynamic_flags()
329 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
330 {
331 Ok(InstanceRequest::_UnknownMethod {
332 ordinal: header.ordinal,
333 control_handle: InstanceControlHandle { inner: this.inner.clone() },
334 method_type: fidl::MethodType::OneWay,
335 })
336 }
337 _ if header
338 .dynamic_flags()
339 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
340 {
341 this.inner.send_framework_err(
342 fidl::encoding::FrameworkErr::UnknownMethod,
343 header.tx_id,
344 header.ordinal,
345 header.dynamic_flags(),
346 (bytes, handles),
347 )?;
348 Ok(InstanceRequest::_UnknownMethod {
349 ordinal: header.ordinal,
350 control_handle: InstanceControlHandle { inner: this.inner.clone() },
351 method_type: fidl::MethodType::TwoWay,
352 })
353 }
354 _ => Err(fidl::Error::UnknownOrdinal {
355 ordinal: header.ordinal,
356 protocol_name:
357 <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
358 }),
359 }))
360 },
361 )
362 }
363}
364
365#[derive(Debug)]
368pub enum InstanceRequest {
369 AddLine { line: [Point; 2], control_handle: InstanceControlHandle },
371 #[non_exhaustive]
373 _UnknownMethod {
374 ordinal: u64,
376 control_handle: InstanceControlHandle,
377 method_type: fidl::MethodType,
378 },
379}
380
381impl InstanceRequest {
382 #[allow(irrefutable_let_patterns)]
383 pub fn into_add_line(self) -> Option<([Point; 2], InstanceControlHandle)> {
384 if let InstanceRequest::AddLine { line, control_handle } = self {
385 Some((line, control_handle))
386 } else {
387 None
388 }
389 }
390
391 pub fn method_name(&self) -> &'static str {
393 match *self {
394 InstanceRequest::AddLine { .. } => "add_line",
395 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
396 "unknown one-way method"
397 }
398 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
399 "unknown two-way method"
400 }
401 }
402 }
403}
404
405#[derive(Debug, Clone)]
406pub struct InstanceControlHandle {
407 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
408}
409
410impl fidl::endpoints::ControlHandle for InstanceControlHandle {
411 fn shutdown(&self) {
412 self.inner.shutdown()
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}