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#[derive(Debug, Clone)]
103pub struct InstanceProxy {
104 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
105}
106
107impl fidl::endpoints::Proxy for InstanceProxy {
108 type Protocol = InstanceMarker;
109
110 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
111 Self::new(inner)
112 }
113
114 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
115 self.client.into_channel().map_err(|client| Self { client })
116 }
117
118 fn as_channel(&self) -> &::fidl::AsyncChannel {
119 self.client.as_channel()
120 }
121}
122
123impl InstanceProxy {
124 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
126 let protocol_name = <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
127 Self { client: fidl::client::Client::new(channel, protocol_name) }
128 }
129
130 pub fn take_event_stream(&self) -> InstanceEventStream {
136 InstanceEventStream { event_receiver: self.client.take_event_receiver() }
137 }
138
139 pub fn r#add_line(
148 &self,
149 mut line: &[Point; 2],
150 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
151 InstanceProxyInterface::r#add_line(self, line)
152 }
153}
154
155impl InstanceProxyInterface for InstanceProxy {
156 type AddLineResponseFut =
157 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
158 fn r#add_line(&self, mut line: &[Point; 2]) -> Self::AddLineResponseFut {
159 fn _decode(
160 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
161 ) -> Result<(), fidl::Error> {
162 let _response = fidl::client::decode_transaction_body::<
163 fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
164 fidl::encoding::DefaultFuchsiaResourceDialect,
165 0x4eff6e5348bfc151,
166 >(_buf?)?
167 .into_result::<InstanceMarker>("add_line")?;
168 Ok(_response)
169 }
170 self.client.send_query_and_decode::<InstanceAddLineRequest, ()>(
171 (line,),
172 0x4eff6e5348bfc151,
173 fidl::encoding::DynamicFlags::FLEXIBLE,
174 _decode,
175 )
176 }
177}
178
179pub struct InstanceEventStream {
180 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
181}
182
183impl std::marker::Unpin for InstanceEventStream {}
184
185impl futures::stream::FusedStream for InstanceEventStream {
186 fn is_terminated(&self) -> bool {
187 self.event_receiver.is_terminated()
188 }
189}
190
191impl futures::Stream for InstanceEventStream {
192 type Item = Result<InstanceEvent, fidl::Error>;
193
194 fn poll_next(
195 mut self: std::pin::Pin<&mut Self>,
196 cx: &mut std::task::Context<'_>,
197 ) -> std::task::Poll<Option<Self::Item>> {
198 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
199 &mut self.event_receiver,
200 cx
201 )?) {
202 Some(buf) => std::task::Poll::Ready(Some(InstanceEvent::decode(buf))),
203 None => std::task::Poll::Ready(None),
204 }
205 }
206}
207
208#[derive(Debug)]
209pub enum InstanceEvent {
210 OnDrawn {
211 top_left: Point,
212 bottom_right: Point,
213 },
214 #[non_exhaustive]
215 _UnknownEvent {
216 ordinal: u64,
218 },
219}
220
221impl InstanceEvent {
222 #[allow(irrefutable_let_patterns)]
223 pub fn into_on_drawn(self) -> Option<(Point, Point)> {
224 if let InstanceEvent::OnDrawn { top_left, bottom_right } = self {
225 Some((top_left, bottom_right))
226 } else {
227 None
228 }
229 }
230
231 fn decode(
233 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
234 ) -> Result<InstanceEvent, fidl::Error> {
235 let (bytes, _handles) = buf.split_mut();
236 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
237 debug_assert_eq!(tx_header.tx_id, 0);
238 match tx_header.ordinal {
239 0x2f9e344d1ce361b7 => {
240 let mut out =
241 fidl::new_empty!(BoundingBox, fidl::encoding::DefaultFuchsiaResourceDialect);
242 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BoundingBox>(&tx_header, _body_bytes, _handles, &mut out)?;
243 Ok((InstanceEvent::OnDrawn {
244 top_left: out.top_left,
245 bottom_right: out.bottom_right,
246 }))
247 }
248 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
249 Ok(InstanceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
250 }
251 _ => Err(fidl::Error::UnknownOrdinal {
252 ordinal: tx_header.ordinal,
253 protocol_name: <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
254 }),
255 }
256 }
257}
258
259pub struct InstanceRequestStream {
261 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
262 is_terminated: bool,
263}
264
265impl std::marker::Unpin for InstanceRequestStream {}
266
267impl futures::stream::FusedStream for InstanceRequestStream {
268 fn is_terminated(&self) -> bool {
269 self.is_terminated
270 }
271}
272
273impl fidl::endpoints::RequestStream for InstanceRequestStream {
274 type Protocol = InstanceMarker;
275 type ControlHandle = InstanceControlHandle;
276
277 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
278 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
279 }
280
281 fn control_handle(&self) -> Self::ControlHandle {
282 InstanceControlHandle { inner: self.inner.clone() }
283 }
284
285 fn into_inner(
286 self,
287 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
288 {
289 (self.inner, self.is_terminated)
290 }
291
292 fn from_inner(
293 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
294 is_terminated: bool,
295 ) -> Self {
296 Self { inner, is_terminated }
297 }
298}
299
300impl futures::Stream for InstanceRequestStream {
301 type Item = Result<InstanceRequest, fidl::Error>;
302
303 fn poll_next(
304 mut self: std::pin::Pin<&mut Self>,
305 cx: &mut std::task::Context<'_>,
306 ) -> std::task::Poll<Option<Self::Item>> {
307 let this = &mut *self;
308 if this.inner.check_shutdown(cx) {
309 this.is_terminated = true;
310 return std::task::Poll::Ready(None);
311 }
312 if this.is_terminated {
313 panic!("polled InstanceRequestStream after completion");
314 }
315 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
316 |bytes, handles| {
317 match this.inner.channel().read_etc(cx, bytes, handles) {
318 std::task::Poll::Ready(Ok(())) => {}
319 std::task::Poll::Pending => return std::task::Poll::Pending,
320 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
321 this.is_terminated = true;
322 return std::task::Poll::Ready(None);
323 }
324 std::task::Poll::Ready(Err(e)) => {
325 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
326 e.into(),
327 ))))
328 }
329 }
330
331 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
333
334 std::task::Poll::Ready(Some(match header.ordinal {
335 0x4eff6e5348bfc151 => {
336 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
337 let mut req = fidl::new_empty!(
338 InstanceAddLineRequest,
339 fidl::encoding::DefaultFuchsiaResourceDialect
340 );
341 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InstanceAddLineRequest>(&header, _body_bytes, handles, &mut req)?;
342 let control_handle = InstanceControlHandle { inner: this.inner.clone() };
343 Ok(InstanceRequest::AddLine {
344 line: req.line,
345
346 responder: InstanceAddLineResponder {
347 control_handle: std::mem::ManuallyDrop::new(control_handle),
348 tx_id: header.tx_id,
349 },
350 })
351 }
352 _ if header.tx_id == 0
353 && header
354 .dynamic_flags()
355 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
356 {
357 Ok(InstanceRequest::_UnknownMethod {
358 ordinal: header.ordinal,
359 control_handle: InstanceControlHandle { inner: this.inner.clone() },
360 method_type: fidl::MethodType::OneWay,
361 })
362 }
363 _ if header
364 .dynamic_flags()
365 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
366 {
367 this.inner.send_framework_err(
368 fidl::encoding::FrameworkErr::UnknownMethod,
369 header.tx_id,
370 header.ordinal,
371 header.dynamic_flags(),
372 (bytes, handles),
373 )?;
374 Ok(InstanceRequest::_UnknownMethod {
375 ordinal: header.ordinal,
376 control_handle: InstanceControlHandle { inner: this.inner.clone() },
377 method_type: fidl::MethodType::TwoWay,
378 })
379 }
380 _ => Err(fidl::Error::UnknownOrdinal {
381 ordinal: header.ordinal,
382 protocol_name:
383 <InstanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
384 }),
385 }))
386 },
387 )
388 }
389}
390
391#[derive(Debug)]
394pub enum InstanceRequest {
395 AddLine { line: [Point; 2], responder: InstanceAddLineResponder },
404 #[non_exhaustive]
406 _UnknownMethod {
407 ordinal: u64,
409 control_handle: InstanceControlHandle,
410 method_type: fidl::MethodType,
411 },
412}
413
414impl InstanceRequest {
415 #[allow(irrefutable_let_patterns)]
416 pub fn into_add_line(self) -> Option<([Point; 2], InstanceAddLineResponder)> {
417 if let InstanceRequest::AddLine { line, responder } = self {
418 Some((line, responder))
419 } else {
420 None
421 }
422 }
423
424 pub fn method_name(&self) -> &'static str {
426 match *self {
427 InstanceRequest::AddLine { .. } => "add_line",
428 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
429 "unknown one-way method"
430 }
431 InstanceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
432 "unknown two-way method"
433 }
434 }
435 }
436}
437
438#[derive(Debug, Clone)]
439pub struct InstanceControlHandle {
440 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
441}
442
443impl fidl::endpoints::ControlHandle for InstanceControlHandle {
444 fn shutdown(&self) {
445 self.inner.shutdown()
446 }
447 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
448 self.inner.shutdown_with_epitaph(status)
449 }
450
451 fn is_closed(&self) -> bool {
452 self.inner.channel().is_closed()
453 }
454 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
455 self.inner.channel().on_closed()
456 }
457
458 #[cfg(target_os = "fuchsia")]
459 fn signal_peer(
460 &self,
461 clear_mask: zx::Signals,
462 set_mask: zx::Signals,
463 ) -> Result<(), zx_status::Status> {
464 use fidl::Peered;
465 self.inner.channel().signal_peer(clear_mask, set_mask)
466 }
467}
468
469impl InstanceControlHandle {
470 pub fn send_on_drawn(
471 &self,
472 mut top_left: &Point,
473 mut bottom_right: &Point,
474 ) -> Result<(), fidl::Error> {
475 self.inner.send::<BoundingBox>(
476 (top_left, bottom_right),
477 0,
478 0x2f9e344d1ce361b7,
479 fidl::encoding::DynamicFlags::FLEXIBLE,
480 )
481 }
482}
483
484#[must_use = "FIDL methods require a response to be sent"]
485#[derive(Debug)]
486pub struct InstanceAddLineResponder {
487 control_handle: std::mem::ManuallyDrop<InstanceControlHandle>,
488 tx_id: u32,
489}
490
491impl std::ops::Drop for InstanceAddLineResponder {
495 fn drop(&mut self) {
496 self.control_handle.shutdown();
497 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
499 }
500}
501
502impl fidl::endpoints::Responder for InstanceAddLineResponder {
503 type ControlHandle = InstanceControlHandle;
504
505 fn control_handle(&self) -> &InstanceControlHandle {
506 &self.control_handle
507 }
508
509 fn drop_without_shutdown(mut self) {
510 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
512 std::mem::forget(self);
514 }
515}
516
517impl InstanceAddLineResponder {
518 pub fn send(self) -> Result<(), fidl::Error> {
522 let _result = self.send_raw();
523 if _result.is_err() {
524 self.control_handle.shutdown();
525 }
526 self.drop_without_shutdown();
527 _result
528 }
529
530 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
532 let _result = self.send_raw();
533 self.drop_without_shutdown();
534 _result
535 }
536
537 fn send_raw(&self) -> Result<(), fidl::Error> {
538 self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
539 fidl::encoding::Flexible::new(()),
540 self.tx_id,
541 0x4eff6e5348bfc151,
542 fidl::encoding::DynamicFlags::FLEXIBLE,
543 )
544 }
545}
546
547mod internal {
548 use super::*;
549}