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#[derive(Debug, Clone)]
113pub struct InstanceProxy {
114 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
115}
116
117impl fidl::endpoints::Proxy for InstanceProxy {
118 type Protocol = InstanceMarker;
119
120 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
121 Self::new(inner)
122 }
123
124 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
125 self.client.into_channel().map_err(|client| Self { client })
126 }
127
128 fn as_channel(&self) -> &::fidl::AsyncChannel {
129 self.client.as_channel()
130 }
131}
132
133impl InstanceProxy {
134 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
136 let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
137 Self { client: fidl::client::Client::new(channel, protocol_name) }
138 }
139
140 pub fn take_event_stream(&self) -> InstanceEventStream {
146 InstanceEventStream { event_receiver: self.client.take_event_receiver() }
147 }
148
149 pub fn r#add_lines(&self, mut lines: &[[Point; 2]]) -> Result<(), fidl::Error> {
153 InstanceProxyInterface::r#add_lines(self, lines)
154 }
155
156 pub fn r#ready(
167 &self,
168 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
169 InstanceProxyInterface::r#ready(self)
170 }
171}
172
173impl InstanceProxyInterface for InstanceProxy {
174 fn r#add_lines(&self, mut lines: &[[Point; 2]]) -> Result<(), fidl::Error> {
175 self.client.send::<InstanceAddLinesRequest>(
176 (lines,),
177 0x5a82f0b30f970bd6,
178 fidl::encoding::DynamicFlags::FLEXIBLE,
179 )
180 }
181
182 type ReadyResponseFut =
183 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
184 fn r#ready(&self) -> Self::ReadyResponseFut {
185 fn _decode(
186 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
187 ) -> Result<(), fidl::Error> {
188 let _response = fidl::client::decode_transaction_body::<
189 fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
190 fidl::encoding::DefaultFuchsiaResourceDialect,
191 0x3458d7a668873150,
192 >(_buf?)?
193 .into_result::<InstanceMarker>("ready")?;
194 Ok(_response)
195 }
196 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
197 (),
198 0x3458d7a668873150,
199 fidl::encoding::DynamicFlags::FLEXIBLE,
200 _decode,
201 )
202 }
203}
204
205pub struct InstanceEventStream {
206 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
207}
208
209impl std::marker::Unpin for InstanceEventStream {}
210
211impl futures::stream::FusedStream for InstanceEventStream {
212 fn is_terminated(&self) -> bool {
213 self.event_receiver.is_terminated()
214 }
215}
216
217impl futures::Stream for InstanceEventStream {
218 type Item = Result<InstanceEvent, fidl::Error>;
219
220 fn poll_next(
221 mut self: std::pin::Pin<&mut Self>,
222 cx: &mut std::task::Context<'_>,
223 ) -> std::task::Poll<Option<Self::Item>> {
224 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
225 &mut self.event_receiver,
226 cx
227 )?) {
228 Some(buf) => std::task::Poll::Ready(Some(InstanceEvent::decode(buf))),
229 None => std::task::Poll::Ready(None),
230 }
231 }
232}
233
234#[derive(Debug)]
235pub enum InstanceEvent {
236 OnDrawn {
237 top_left: Point,
238 bottom_right: Point,
239 },
240 #[non_exhaustive]
241 _UnknownEvent {
242 ordinal: u64,
244 },
245}
246
247impl InstanceEvent {
248 #[allow(irrefutable_let_patterns)]
249 pub fn into_on_drawn(self) -> Option<(Point, Point)> {
250 if let InstanceEvent::OnDrawn { top_left, bottom_right } = self {
251 Some((top_left, bottom_right))
252 } else {
253 None
254 }
255 }
256
257 fn decode(
259 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
260 ) -> Result<InstanceEvent, fidl::Error> {
261 let (bytes, _handles) = buf.split_mut();
262 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
263 debug_assert_eq!(tx_header.tx_id, 0);
264 match tx_header.ordinal {
265 0x25e6d8494623419a => {
266 let mut out =
267 fidl::new_empty!(BoundingBox, fidl::encoding::DefaultFuchsiaResourceDialect);
268 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BoundingBox>(&tx_header, _body_bytes, _handles, &mut out)?;
269 Ok((InstanceEvent::OnDrawn {
270 top_left: out.top_left,
271 bottom_right: out.bottom_right,
272 }))
273 }
274 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
275 Ok(InstanceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
276 }
277 _ => Err(fidl::Error::UnknownOrdinal {
278 ordinal: tx_header.ordinal,
279 protocol_name: <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
280 }),
281 }
282 }
283}
284
285pub struct InstanceRequestStream {
287 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
288 is_terminated: bool,
289}
290
291impl std::marker::Unpin for InstanceRequestStream {}
292
293impl futures::stream::FusedStream for InstanceRequestStream {
294 fn is_terminated(&self) -> bool {
295 self.is_terminated
296 }
297}
298
299impl fidl::endpoints::RequestStream for InstanceRequestStream {
300 type Protocol = InstanceMarker;
301 type ControlHandle = InstanceControlHandle;
302
303 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
304 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
305 }
306
307 fn control_handle(&self) -> Self::ControlHandle {
308 InstanceControlHandle { inner: self.inner.clone() }
309 }
310
311 fn into_inner(
312 self,
313 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
314 {
315 (self.inner, self.is_terminated)
316 }
317
318 fn from_inner(
319 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
320 is_terminated: bool,
321 ) -> Self {
322 Self { inner, is_terminated }
323 }
324}
325
326impl futures::Stream for InstanceRequestStream {
327 type Item = Result<InstanceRequest, fidl::Error>;
328
329 fn poll_next(
330 mut self: std::pin::Pin<&mut Self>,
331 cx: &mut std::task::Context<'_>,
332 ) -> std::task::Poll<Option<Self::Item>> {
333 let this = &mut *self;
334 if this.inner.check_shutdown(cx) {
335 this.is_terminated = true;
336 return std::task::Poll::Ready(None);
337 }
338 if this.is_terminated {
339 panic!("polled InstanceRequestStream after completion");
340 }
341 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
342 |bytes, handles| {
343 match this.inner.channel().read_etc(cx, bytes, handles) {
344 std::task::Poll::Ready(Ok(())) => {}
345 std::task::Poll::Pending => return std::task::Poll::Pending,
346 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
347 this.is_terminated = true;
348 return std::task::Poll::Ready(None);
349 }
350 std::task::Poll::Ready(Err(e)) => {
351 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
352 e.into(),
353 ))))
354 }
355 }
356
357 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
359
360 std::task::Poll::Ready(Some(match header.ordinal {
361 0x5a82f0b30f970bd6 => {
362 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
363 let mut req = fidl::new_empty!(
364 InstanceAddLinesRequest,
365 fidl::encoding::DefaultFuchsiaResourceDialect
366 );
367 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InstanceAddLinesRequest>(&header, _body_bytes, handles, &mut req)?;
368 let control_handle = InstanceControlHandle { inner: this.inner.clone() };
369 Ok(InstanceRequest::AddLines { lines: req.lines, control_handle })
370 }
371 0x3458d7a668873150 => {
372 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
373 let mut req = fidl::new_empty!(
374 fidl::encoding::EmptyPayload,
375 fidl::encoding::DefaultFuchsiaResourceDialect
376 );
377 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
378 let control_handle = InstanceControlHandle { inner: this.inner.clone() };
379 Ok(InstanceRequest::Ready {
380 responder: InstanceReadyResponder {
381 control_handle: std::mem::ManuallyDrop::new(control_handle),
382 tx_id: header.tx_id,
383 },
384 })
385 }
386 _ if header.tx_id == 0
387 && header
388 .dynamic_flags()
389 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
390 {
391 Ok(InstanceRequest::_UnknownMethod {
392 ordinal: header.ordinal,
393 control_handle: InstanceControlHandle { inner: this.inner.clone() },
394 method_type: fidl::MethodType::OneWay,
395 })
396 }
397 _ if header
398 .dynamic_flags()
399 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
400 {
401 this.inner.send_framework_err(
402 fidl::encoding::FrameworkErr::UnknownMethod,
403 header.tx_id,
404 header.ordinal,
405 header.dynamic_flags(),
406 (bytes, handles),
407 )?;
408 Ok(InstanceRequest::_UnknownMethod {
409 ordinal: header.ordinal,
410 control_handle: InstanceControlHandle { inner: this.inner.clone() },
411 method_type: fidl::MethodType::TwoWay,
412 })
413 }
414 _ => Err(fidl::Error::UnknownOrdinal {
415 ordinal: header.ordinal,
416 protocol_name:
417 <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
418 }),
419 }))
420 },
421 )
422 }
423}
424
425#[derive(Debug)]
428pub enum InstanceRequest {
429 AddLines { lines: Vec<[Point; 2]>, control_handle: InstanceControlHandle },
433 Ready { responder: InstanceReadyResponder },
444 #[non_exhaustive]
446 _UnknownMethod {
447 ordinal: u64,
449 control_handle: InstanceControlHandle,
450 method_type: fidl::MethodType,
451 },
452}
453
454impl InstanceRequest {
455 #[allow(irrefutable_let_patterns)]
456 pub fn into_add_lines(self) -> Option<(Vec<[Point; 2]>, InstanceControlHandle)> {
457 if let InstanceRequest::AddLines { lines, control_handle } = self {
458 Some((lines, control_handle))
459 } else {
460 None
461 }
462 }
463
464 #[allow(irrefutable_let_patterns)]
465 pub fn into_ready(self) -> Option<(InstanceReadyResponder)> {
466 if let InstanceRequest::Ready { responder } = self {
467 Some((responder))
468 } else {
469 None
470 }
471 }
472
473 pub fn method_name(&self) -> &'static str {
475 match *self {
476 InstanceRequest::AddLines { .. } => "add_lines",
477 InstanceRequest::Ready { .. } => "ready",
478 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
479 "unknown one-way method"
480 }
481 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
482 "unknown two-way method"
483 }
484 }
485 }
486}
487
488#[derive(Debug, Clone)]
489pub struct InstanceControlHandle {
490 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
491}
492
493impl fidl::endpoints::ControlHandle for InstanceControlHandle {
494 fn shutdown(&self) {
495 self.inner.shutdown()
496 }
497 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
498 self.inner.shutdown_with_epitaph(status)
499 }
500
501 fn is_closed(&self) -> bool {
502 self.inner.channel().is_closed()
503 }
504 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
505 self.inner.channel().on_closed()
506 }
507
508 #[cfg(target_os = "fuchsia")]
509 fn signal_peer(
510 &self,
511 clear_mask: zx::Signals,
512 set_mask: zx::Signals,
513 ) -> Result<(), zx_status::Status> {
514 use fidl::Peered;
515 self.inner.channel().signal_peer(clear_mask, set_mask)
516 }
517}
518
519impl InstanceControlHandle {
520 pub fn send_on_drawn(
521 &self,
522 mut top_left: &Point,
523 mut bottom_right: &Point,
524 ) -> Result<(), fidl::Error> {
525 self.inner.send::<BoundingBox>(
526 (top_left, bottom_right),
527 0,
528 0x25e6d8494623419a,
529 fidl::encoding::DynamicFlags::FLEXIBLE,
530 )
531 }
532}
533
534#[must_use = "FIDL methods require a response to be sent"]
535#[derive(Debug)]
536pub struct InstanceReadyResponder {
537 control_handle: std::mem::ManuallyDrop<InstanceControlHandle>,
538 tx_id: u32,
539}
540
541impl std::ops::Drop for InstanceReadyResponder {
545 fn drop(&mut self) {
546 self.control_handle.shutdown();
547 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
549 }
550}
551
552impl fidl::endpoints::Responder for InstanceReadyResponder {
553 type ControlHandle = InstanceControlHandle;
554
555 fn control_handle(&self) -> &InstanceControlHandle {
556 &self.control_handle
557 }
558
559 fn drop_without_shutdown(mut self) {
560 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
562 std::mem::forget(self);
564 }
565}
566
567impl InstanceReadyResponder {
568 pub fn send(self) -> Result<(), fidl::Error> {
572 let _result = self.send_raw();
573 if _result.is_err() {
574 self.control_handle.shutdown();
575 }
576 self.drop_without_shutdown();
577 _result
578 }
579
580 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
582 let _result = self.send_raw();
583 self.drop_without_shutdown();
584 _result
585 }
586
587 fn send_raw(&self) -> Result<(), fidl::Error> {
588 self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
589 fidl::encoding::Flexible::new(()),
590 self.tx_id,
591 0x3458d7a668873150,
592 fidl::encoding::DynamicFlags::FLEXIBLE,
593 )
594 }
595}
596
597mod internal {
598 use super::*;
599}