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_addlinemetered__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.addlinemetered.Instance";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for InstanceMarker {}
26
27pub trait InstanceProxyInterface: Send + Sync {
28 type AddLineResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29 fn r#add_line(&self, line: &[Point; 2]) -> Self::AddLineResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct InstanceSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for InstanceSynchronousProxy {
39 type Proxy = InstanceProxy;
40 type Protocol = InstanceMarker;
41
42 fn from_channel(inner: fidl::Channel) -> Self {
43 Self::new(inner)
44 }
45
46 fn into_channel(self) -> fidl::Channel {
47 self.client.into_channel()
48 }
49
50 fn as_channel(&self) -> &fidl::Channel {
51 self.client.as_channel()
52 }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl InstanceSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60 }
61
62 pub fn into_channel(self) -> fidl::Channel {
63 self.client.into_channel()
64 }
65
66 pub fn wait_for_event(
69 &self,
70 deadline: zx::MonotonicInstant,
71 ) -> Result<InstanceEvent, fidl::Error> {
72 InstanceEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#add_line(
84 &self,
85 mut line: &[Point; 2],
86 ___deadline: zx::MonotonicInstant,
87 ) -> Result<(), fidl::Error> {
88 let _response = self.client.send_query::<
89 InstanceAddLineRequest,
90 fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
91 >(
92 (line,),
93 0x4eff6e5348bfc151,
94 fidl::encoding::DynamicFlags::FLEXIBLE,
95 ___deadline,
96 )?
97 .into_result::<InstanceMarker>("add_line")?;
98 Ok(_response)
99 }
100}
101
102#[cfg(target_os = "fuchsia")]
103impl From<InstanceSynchronousProxy> for zx::Handle {
104 fn from(value: InstanceSynchronousProxy) -> Self {
105 value.into_channel().into()
106 }
107}
108
109#[cfg(target_os = "fuchsia")]
110impl From<fidl::Channel> for InstanceSynchronousProxy {
111 fn from(value: fidl::Channel) -> Self {
112 Self::new(value)
113 }
114}
115
116#[cfg(target_os = "fuchsia")]
117impl fidl::endpoints::FromClient for InstanceSynchronousProxy {
118 type Protocol = InstanceMarker;
119
120 fn from_client(value: fidl::endpoints::ClientEnd<InstanceMarker>) -> Self {
121 Self::new(value.into_channel())
122 }
123}
124
125#[derive(Debug, Clone)]
126pub struct InstanceProxy {
127 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
128}
129
130impl fidl::endpoints::Proxy for InstanceProxy {
131 type Protocol = InstanceMarker;
132
133 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
134 Self::new(inner)
135 }
136
137 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
138 self.client.into_channel().map_err(|client| Self { client })
139 }
140
141 fn as_channel(&self) -> &::fidl::AsyncChannel {
142 self.client.as_channel()
143 }
144}
145
146impl InstanceProxy {
147 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
149 let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
150 Self { client: fidl::client::Client::new(channel, protocol_name) }
151 }
152
153 pub fn take_event_stream(&self) -> InstanceEventStream {
159 InstanceEventStream { event_receiver: self.client.take_event_receiver() }
160 }
161
162 pub fn r#add_line(
171 &self,
172 mut line: &[Point; 2],
173 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
174 InstanceProxyInterface::r#add_line(self, line)
175 }
176}
177
178impl InstanceProxyInterface for InstanceProxy {
179 type AddLineResponseFut =
180 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
181 fn r#add_line(&self, mut line: &[Point; 2]) -> Self::AddLineResponseFut {
182 fn _decode(
183 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
184 ) -> Result<(), fidl::Error> {
185 let _response = fidl::client::decode_transaction_body::<
186 fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
187 fidl::encoding::DefaultFuchsiaResourceDialect,
188 0x4eff6e5348bfc151,
189 >(_buf?)?
190 .into_result::<InstanceMarker>("add_line")?;
191 Ok(_response)
192 }
193 self.client.send_query_and_decode::<InstanceAddLineRequest, ()>(
194 (line,),
195 0x4eff6e5348bfc151,
196 fidl::encoding::DynamicFlags::FLEXIBLE,
197 _decode,
198 )
199 }
200}
201
202pub struct InstanceEventStream {
203 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
204}
205
206impl std::marker::Unpin for InstanceEventStream {}
207
208impl futures::stream::FusedStream for InstanceEventStream {
209 fn is_terminated(&self) -> bool {
210 self.event_receiver.is_terminated()
211 }
212}
213
214impl futures::Stream for InstanceEventStream {
215 type Item = Result<InstanceEvent, fidl::Error>;
216
217 fn poll_next(
218 mut self: std::pin::Pin<&mut Self>,
219 cx: &mut std::task::Context<'_>,
220 ) -> std::task::Poll<Option<Self::Item>> {
221 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
222 &mut self.event_receiver,
223 cx
224 )?) {
225 Some(buf) => std::task::Poll::Ready(Some(InstanceEvent::decode(buf))),
226 None => std::task::Poll::Ready(None),
227 }
228 }
229}
230
231#[derive(Debug)]
232pub enum InstanceEvent {
233 OnDrawn {
234 top_left: Point,
235 bottom_right: Point,
236 },
237 #[non_exhaustive]
238 _UnknownEvent {
239 ordinal: u64,
241 },
242}
243
244impl InstanceEvent {
245 #[allow(irrefutable_let_patterns)]
246 pub fn into_on_drawn(self) -> Option<(Point, Point)> {
247 if let InstanceEvent::OnDrawn { top_left, bottom_right } = self {
248 Some((top_left, bottom_right))
249 } else {
250 None
251 }
252 }
253
254 fn decode(
256 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
257 ) -> Result<InstanceEvent, fidl::Error> {
258 let (bytes, _handles) = buf.split_mut();
259 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
260 debug_assert_eq!(tx_header.tx_id, 0);
261 match tx_header.ordinal {
262 0x2f9e344d1ce361b7 => {
263 let mut out =
264 fidl::new_empty!(BoundingBox, fidl::encoding::DefaultFuchsiaResourceDialect);
265 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BoundingBox>(&tx_header, _body_bytes, _handles, &mut out)?;
266 Ok((InstanceEvent::OnDrawn {
267 top_left: out.top_left,
268 bottom_right: out.bottom_right,
269 }))
270 }
271 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
272 Ok(InstanceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
273 }
274 _ => Err(fidl::Error::UnknownOrdinal {
275 ordinal: tx_header.ordinal,
276 protocol_name: <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
277 }),
278 }
279 }
280}
281
282pub struct InstanceRequestStream {
284 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
285 is_terminated: bool,
286}
287
288impl std::marker::Unpin for InstanceRequestStream {}
289
290impl futures::stream::FusedStream for InstanceRequestStream {
291 fn is_terminated(&self) -> bool {
292 self.is_terminated
293 }
294}
295
296impl fidl::endpoints::RequestStream for InstanceRequestStream {
297 type Protocol = InstanceMarker;
298 type ControlHandle = InstanceControlHandle;
299
300 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
301 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
302 }
303
304 fn control_handle(&self) -> Self::ControlHandle {
305 InstanceControlHandle { inner: self.inner.clone() }
306 }
307
308 fn into_inner(
309 self,
310 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
311 {
312 (self.inner, self.is_terminated)
313 }
314
315 fn from_inner(
316 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
317 is_terminated: bool,
318 ) -> Self {
319 Self { inner, is_terminated }
320 }
321}
322
323impl futures::Stream for InstanceRequestStream {
324 type Item = Result<InstanceRequest, fidl::Error>;
325
326 fn poll_next(
327 mut self: std::pin::Pin<&mut Self>,
328 cx: &mut std::task::Context<'_>,
329 ) -> std::task::Poll<Option<Self::Item>> {
330 let this = &mut *self;
331 if this.inner.check_shutdown(cx) {
332 this.is_terminated = true;
333 return std::task::Poll::Ready(None);
334 }
335 if this.is_terminated {
336 panic!("polled InstanceRequestStream after completion");
337 }
338 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
339 |bytes, handles| {
340 match this.inner.channel().read_etc(cx, bytes, handles) {
341 std::task::Poll::Ready(Ok(())) => {}
342 std::task::Poll::Pending => return std::task::Poll::Pending,
343 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
344 this.is_terminated = true;
345 return std::task::Poll::Ready(None);
346 }
347 std::task::Poll::Ready(Err(e)) => {
348 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
349 e.into(),
350 ))))
351 }
352 }
353
354 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
356
357 std::task::Poll::Ready(Some(match header.ordinal {
358 0x4eff6e5348bfc151 => {
359 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
360 let mut req = fidl::new_empty!(
361 InstanceAddLineRequest,
362 fidl::encoding::DefaultFuchsiaResourceDialect
363 );
364 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InstanceAddLineRequest>(&header, _body_bytes, handles, &mut req)?;
365 let control_handle = InstanceControlHandle { inner: this.inner.clone() };
366 Ok(InstanceRequest::AddLine {
367 line: req.line,
368
369 responder: InstanceAddLineResponder {
370 control_handle: std::mem::ManuallyDrop::new(control_handle),
371 tx_id: header.tx_id,
372 },
373 })
374 }
375 _ if header.tx_id == 0
376 && header
377 .dynamic_flags()
378 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
379 {
380 Ok(InstanceRequest::_UnknownMethod {
381 ordinal: header.ordinal,
382 control_handle: InstanceControlHandle { inner: this.inner.clone() },
383 method_type: fidl::MethodType::OneWay,
384 })
385 }
386 _ if header
387 .dynamic_flags()
388 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
389 {
390 this.inner.send_framework_err(
391 fidl::encoding::FrameworkErr::UnknownMethod,
392 header.tx_id,
393 header.ordinal,
394 header.dynamic_flags(),
395 (bytes, handles),
396 )?;
397 Ok(InstanceRequest::_UnknownMethod {
398 ordinal: header.ordinal,
399 control_handle: InstanceControlHandle { inner: this.inner.clone() },
400 method_type: fidl::MethodType::TwoWay,
401 })
402 }
403 _ => Err(fidl::Error::UnknownOrdinal {
404 ordinal: header.ordinal,
405 protocol_name:
406 <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
407 }),
408 }))
409 },
410 )
411 }
412}
413
414#[derive(Debug)]
417pub enum InstanceRequest {
418 AddLine { line: [Point; 2], responder: InstanceAddLineResponder },
427 #[non_exhaustive]
429 _UnknownMethod {
430 ordinal: u64,
432 control_handle: InstanceControlHandle,
433 method_type: fidl::MethodType,
434 },
435}
436
437impl InstanceRequest {
438 #[allow(irrefutable_let_patterns)]
439 pub fn into_add_line(self) -> Option<([Point; 2], InstanceAddLineResponder)> {
440 if let InstanceRequest::AddLine { line, responder } = self {
441 Some((line, responder))
442 } else {
443 None
444 }
445 }
446
447 pub fn method_name(&self) -> &'static str {
449 match *self {
450 InstanceRequest::AddLine { .. } => "add_line",
451 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
452 "unknown one-way method"
453 }
454 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
455 "unknown two-way method"
456 }
457 }
458 }
459}
460
461#[derive(Debug, Clone)]
462pub struct InstanceControlHandle {
463 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
464}
465
466impl fidl::endpoints::ControlHandle for InstanceControlHandle {
467 fn shutdown(&self) {
468 self.inner.shutdown()
469 }
470 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
471 self.inner.shutdown_with_epitaph(status)
472 }
473
474 fn is_closed(&self) -> bool {
475 self.inner.channel().is_closed()
476 }
477 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
478 self.inner.channel().on_closed()
479 }
480
481 #[cfg(target_os = "fuchsia")]
482 fn signal_peer(
483 &self,
484 clear_mask: zx::Signals,
485 set_mask: zx::Signals,
486 ) -> Result<(), zx_status::Status> {
487 use fidl::Peered;
488 self.inner.channel().signal_peer(clear_mask, set_mask)
489 }
490}
491
492impl InstanceControlHandle {
493 pub fn send_on_drawn(
494 &self,
495 mut top_left: &Point,
496 mut bottom_right: &Point,
497 ) -> Result<(), fidl::Error> {
498 self.inner.send::<BoundingBox>(
499 (top_left, bottom_right),
500 0,
501 0x2f9e344d1ce361b7,
502 fidl::encoding::DynamicFlags::FLEXIBLE,
503 )
504 }
505}
506
507#[must_use = "FIDL methods require a response to be sent"]
508#[derive(Debug)]
509pub struct InstanceAddLineResponder {
510 control_handle: std::mem::ManuallyDrop<InstanceControlHandle>,
511 tx_id: u32,
512}
513
514impl std::ops::Drop for InstanceAddLineResponder {
518 fn drop(&mut self) {
519 self.control_handle.shutdown();
520 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
522 }
523}
524
525impl fidl::endpoints::Responder for InstanceAddLineResponder {
526 type ControlHandle = InstanceControlHandle;
527
528 fn control_handle(&self) -> &InstanceControlHandle {
529 &self.control_handle
530 }
531
532 fn drop_without_shutdown(mut self) {
533 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
535 std::mem::forget(self);
537 }
538}
539
540impl InstanceAddLineResponder {
541 pub fn send(self) -> Result<(), fidl::Error> {
545 let _result = self.send_raw();
546 if _result.is_err() {
547 self.control_handle.shutdown();
548 }
549 self.drop_without_shutdown();
550 _result
551 }
552
553 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
555 let _result = self.send_raw();
556 self.drop_without_shutdown();
557 _result
558 }
559
560 fn send_raw(&self) -> Result<(), fidl::Error> {
561 self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
562 fidl::encoding::Flexible::new(()),
563 self.tx_id,
564 0x4eff6e5348bfc151,
565 fidl::encoding::DynamicFlags::FLEXIBLE,
566 )
567 }
568}
569
570mod internal {
571 use super::*;
572}