Skip to main content

fidl_fuchsia_examples_calculator/
fidl_fuchsia_examples_calculator.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_fuchsia_examples_calculator__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct CalculatorMarker;
16
17impl fidl::endpoints::ProtocolMarker for CalculatorMarker {
18    type Proxy = CalculatorProxy;
19    type RequestStream = CalculatorRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = CalculatorSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.examples.calculator.Calculator";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for CalculatorMarker {}
26
27pub trait CalculatorProxyInterface: Send + Sync {
28    type AddResponseFut: std::future::Future<Output = Result<f64, fidl::Error>> + Send;
29    fn r#add(&self, a: f64, b: f64) -> Self::AddResponseFut;
30    type SubtractResponseFut: std::future::Future<Output = Result<f64, fidl::Error>> + Send;
31    fn r#subtract(&self, a: f64, b: f64) -> Self::SubtractResponseFut;
32    type MultiplyResponseFut: std::future::Future<Output = Result<f64, fidl::Error>> + Send;
33    fn r#multiply(&self, a: f64, b: f64) -> Self::MultiplyResponseFut;
34    type DivideResponseFut: std::future::Future<Output = Result<f64, fidl::Error>> + Send;
35    fn r#divide(&self, dividend: f64, divisor: f64) -> Self::DivideResponseFut;
36    type PowResponseFut: std::future::Future<Output = Result<f64, fidl::Error>> + Send;
37    fn r#pow(&self, base: f64, exponent: f64) -> Self::PowResponseFut;
38}
39#[derive(Debug)]
40#[cfg(target_os = "fuchsia")]
41pub struct CalculatorSynchronousProxy {
42    client: fidl::client::sync::Client,
43}
44
45#[cfg(target_os = "fuchsia")]
46impl fidl::endpoints::SynchronousProxy for CalculatorSynchronousProxy {
47    type Proxy = CalculatorProxy;
48    type Protocol = CalculatorMarker;
49
50    fn from_channel(inner: fidl::Channel) -> Self {
51        Self::new(inner)
52    }
53
54    fn into_channel(self) -> fidl::Channel {
55        self.client.into_channel()
56    }
57
58    fn as_channel(&self) -> &fidl::Channel {
59        self.client.as_channel()
60    }
61}
62
63#[cfg(target_os = "fuchsia")]
64impl CalculatorSynchronousProxy {
65    pub fn new(channel: fidl::Channel) -> Self {
66        Self { client: fidl::client::sync::Client::new(channel) }
67    }
68
69    pub fn into_channel(self) -> fidl::Channel {
70        self.client.into_channel()
71    }
72
73    /// Waits until an event arrives and returns it. It is safe for other
74    /// threads to make concurrent requests while waiting for an event.
75    pub fn wait_for_event(
76        &self,
77        deadline: zx::MonotonicInstant,
78    ) -> Result<CalculatorEvent, fidl::Error> {
79        CalculatorEvent::decode(self.client.wait_for_event::<CalculatorMarker>(deadline)?)
80    }
81
82    /// Adds two numbers together and returns their `sum`.
83    ///
84    /// For example, with `a` being 4.5 and `b` being 3.2, the response `sum` is
85    /// 7.7.
86    ///
87    /// + request `a` the first number to be added.
88    /// + request `b` the second number to be added.
89    /// - response `sum` the sum of a and b.
90    pub fn r#add(
91        &self,
92        mut a: f64,
93        mut b: f64,
94        ___deadline: zx::MonotonicInstant,
95    ) -> Result<f64, fidl::Error> {
96        let _response = self
97            .client
98            .send_query::<CalculatorAddRequest, CalculatorAddResponse, CalculatorMarker>(
99                (a, b),
100                0x5f2286171d9ff91e,
101                fidl::encoding::DynamicFlags::empty(),
102                ___deadline,
103            )?;
104        Ok(_response.sum)
105    }
106
107    /// Subtracts two numbers and returns their `difference`.
108    ///
109    /// For example, with `a` being 7.7 and `b` being 3.2, the response
110    /// `difference` is 4.5
111    ///
112    /// + request `a` the number to be subracted _from_.
113    /// + request `b` the number to subtract.
114    /// - response `difference` the difference between `a` and `b`.
115    pub fn r#subtract(
116        &self,
117        mut a: f64,
118        mut b: f64,
119        ___deadline: zx::MonotonicInstant,
120    ) -> Result<f64, fidl::Error> {
121        let _response = self
122            .client
123            .send_query::<CalculatorSubtractRequest, CalculatorSubtractResponse, CalculatorMarker>(
124                (a, b),
125                0x64ce8ff043420d78,
126                fidl::encoding::DynamicFlags::empty(),
127                ___deadline,
128            )?;
129        Ok(_response.difference)
130    }
131
132    /// Multiplies two numbers and returns their `product`.
133    ///
134    /// For example, with `a` being 1.5 and `b` being 2.0, the response
135    /// `product` is 3.0
136    ///
137    /// + request `a` the first number used to calculatorulate the `product`.
138    /// + request `b` the second number used to calculatorulate the `product`.
139    /// - response `product` the result of multiplying `a` and `b`.
140    pub fn r#multiply(
141        &self,
142        mut a: f64,
143        mut b: f64,
144        ___deadline: zx::MonotonicInstant,
145    ) -> Result<f64, fidl::Error> {
146        let _response = self
147            .client
148            .send_query::<CalculatorMultiplyRequest, CalculatorMultiplyResponse, CalculatorMarker>(
149                (a, b),
150                0x4d6fedd51609fc35,
151                fidl::encoding::DynamicFlags::empty(),
152                ___deadline,
153            )?;
154        Ok(_response.product)
155    }
156
157    /// Divides one number by another and return the `quotient`.
158    ///
159    /// For example with a `dividend` of 2.0 and a `divisor` of 4.0, the
160    /// response `quotient` is 0.5.
161    ///
162    /// + request `dividend` the number to divide with.
163    /// + request `divisor` the number to divide into.
164    /// - response `quotient` the result of dividing the `dividend` into the `divisor`.
165    pub fn r#divide(
166        &self,
167        mut dividend: f64,
168        mut divisor: f64,
169        ___deadline: zx::MonotonicInstant,
170    ) -> Result<f64, fidl::Error> {
171        let _response = self
172            .client
173            .send_query::<CalculatorDivideRequest, CalculatorDivideResponse, CalculatorMarker>(
174                (dividend, divisor),
175                0x4dc343d7222988ba,
176                fidl::encoding::DynamicFlags::empty(),
177                ___deadline,
178            )?;
179        Ok(_response.quotient)
180    }
181
182    /// Takes `base` to the `exponent` and returns the `power`.
183    ///
184    /// For example with a `base` of 3.0 and an `exponent` of 4.0, the response
185    /// `power` is 81.0.
186    ///
187    /// + request `base` the number to multiply by itself.
188    /// + request `exponent` the number of times to successively multiply
189    /// `base`.
190    /// - response `power` the result of multiplying `base` by itself `exponent`
191    /// times..
192    pub fn r#pow(
193        &self,
194        mut base: f64,
195        mut exponent: f64,
196        ___deadline: zx::MonotonicInstant,
197    ) -> Result<f64, fidl::Error> {
198        let _response = self
199            .client
200            .send_query::<CalculatorPowRequest, CalculatorPowResponse, CalculatorMarker>(
201                (base, exponent),
202                0x3467780dee7ba196,
203                fidl::encoding::DynamicFlags::empty(),
204                ___deadline,
205            )?;
206        Ok(_response.power)
207    }
208}
209
210#[cfg(target_os = "fuchsia")]
211impl From<CalculatorSynchronousProxy> for zx::NullableHandle {
212    fn from(value: CalculatorSynchronousProxy) -> Self {
213        value.into_channel().into()
214    }
215}
216
217#[cfg(target_os = "fuchsia")]
218impl From<fidl::Channel> for CalculatorSynchronousProxy {
219    fn from(value: fidl::Channel) -> Self {
220        Self::new(value)
221    }
222}
223
224#[cfg(target_os = "fuchsia")]
225impl fidl::endpoints::FromClient for CalculatorSynchronousProxy {
226    type Protocol = CalculatorMarker;
227
228    fn from_client(value: fidl::endpoints::ClientEnd<CalculatorMarker>) -> Self {
229        Self::new(value.into_channel())
230    }
231}
232
233#[derive(Debug, Clone)]
234pub struct CalculatorProxy {
235    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
236}
237
238impl fidl::endpoints::Proxy for CalculatorProxy {
239    type Protocol = CalculatorMarker;
240
241    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
242        Self::new(inner)
243    }
244
245    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
246        self.client.into_channel().map_err(|client| Self { client })
247    }
248
249    fn as_channel(&self) -> &::fidl::AsyncChannel {
250        self.client.as_channel()
251    }
252}
253
254impl CalculatorProxy {
255    /// Create a new Proxy for fuchsia.examples.calculator/Calculator.
256    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
257        let protocol_name = <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
258        Self { client: fidl::client::Client::new(channel, protocol_name) }
259    }
260
261    /// Get a Stream of events from the remote end of the protocol.
262    ///
263    /// # Panics
264    ///
265    /// Panics if the event stream was already taken.
266    pub fn take_event_stream(&self) -> CalculatorEventStream {
267        CalculatorEventStream { event_receiver: self.client.take_event_receiver() }
268    }
269
270    /// Adds two numbers together and returns their `sum`.
271    ///
272    /// For example, with `a` being 4.5 and `b` being 3.2, the response `sum` is
273    /// 7.7.
274    ///
275    /// + request `a` the first number to be added.
276    /// + request `b` the second number to be added.
277    /// - response `sum` the sum of a and b.
278    pub fn r#add(
279        &self,
280        mut a: f64,
281        mut b: f64,
282    ) -> fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect> {
283        CalculatorProxyInterface::r#add(self, a, b)
284    }
285
286    /// Subtracts two numbers and returns their `difference`.
287    ///
288    /// For example, with `a` being 7.7 and `b` being 3.2, the response
289    /// `difference` is 4.5
290    ///
291    /// + request `a` the number to be subracted _from_.
292    /// + request `b` the number to subtract.
293    /// - response `difference` the difference between `a` and `b`.
294    pub fn r#subtract(
295        &self,
296        mut a: f64,
297        mut b: f64,
298    ) -> fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect> {
299        CalculatorProxyInterface::r#subtract(self, a, b)
300    }
301
302    /// Multiplies two numbers and returns their `product`.
303    ///
304    /// For example, with `a` being 1.5 and `b` being 2.0, the response
305    /// `product` is 3.0
306    ///
307    /// + request `a` the first number used to calculatorulate the `product`.
308    /// + request `b` the second number used to calculatorulate the `product`.
309    /// - response `product` the result of multiplying `a` and `b`.
310    pub fn r#multiply(
311        &self,
312        mut a: f64,
313        mut b: f64,
314    ) -> fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect> {
315        CalculatorProxyInterface::r#multiply(self, a, b)
316    }
317
318    /// Divides one number by another and return the `quotient`.
319    ///
320    /// For example with a `dividend` of 2.0 and a `divisor` of 4.0, the
321    /// response `quotient` is 0.5.
322    ///
323    /// + request `dividend` the number to divide with.
324    /// + request `divisor` the number to divide into.
325    /// - response `quotient` the result of dividing the `dividend` into the `divisor`.
326    pub fn r#divide(
327        &self,
328        mut dividend: f64,
329        mut divisor: f64,
330    ) -> fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect> {
331        CalculatorProxyInterface::r#divide(self, dividend, divisor)
332    }
333
334    /// Takes `base` to the `exponent` and returns the `power`.
335    ///
336    /// For example with a `base` of 3.0 and an `exponent` of 4.0, the response
337    /// `power` is 81.0.
338    ///
339    /// + request `base` the number to multiply by itself.
340    /// + request `exponent` the number of times to successively multiply
341    /// `base`.
342    /// - response `power` the result of multiplying `base` by itself `exponent`
343    /// times..
344    pub fn r#pow(
345        &self,
346        mut base: f64,
347        mut exponent: f64,
348    ) -> fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect> {
349        CalculatorProxyInterface::r#pow(self, base, exponent)
350    }
351}
352
353impl CalculatorProxyInterface for CalculatorProxy {
354    type AddResponseFut =
355        fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect>;
356    fn r#add(&self, mut a: f64, mut b: f64) -> Self::AddResponseFut {
357        fn _decode(
358            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
359        ) -> Result<f64, fidl::Error> {
360            let _response = fidl::client::decode_transaction_body::<
361                CalculatorAddResponse,
362                fidl::encoding::DefaultFuchsiaResourceDialect,
363                0x5f2286171d9ff91e,
364            >(_buf?)?;
365            Ok(_response.sum)
366        }
367        self.client.send_query_and_decode::<CalculatorAddRequest, f64>(
368            (a, b),
369            0x5f2286171d9ff91e,
370            fidl::encoding::DynamicFlags::empty(),
371            _decode,
372        )
373    }
374
375    type SubtractResponseFut =
376        fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect>;
377    fn r#subtract(&self, mut a: f64, mut b: f64) -> Self::SubtractResponseFut {
378        fn _decode(
379            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
380        ) -> Result<f64, fidl::Error> {
381            let _response = fidl::client::decode_transaction_body::<
382                CalculatorSubtractResponse,
383                fidl::encoding::DefaultFuchsiaResourceDialect,
384                0x64ce8ff043420d78,
385            >(_buf?)?;
386            Ok(_response.difference)
387        }
388        self.client.send_query_and_decode::<CalculatorSubtractRequest, f64>(
389            (a, b),
390            0x64ce8ff043420d78,
391            fidl::encoding::DynamicFlags::empty(),
392            _decode,
393        )
394    }
395
396    type MultiplyResponseFut =
397        fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect>;
398    fn r#multiply(&self, mut a: f64, mut b: f64) -> Self::MultiplyResponseFut {
399        fn _decode(
400            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
401        ) -> Result<f64, fidl::Error> {
402            let _response = fidl::client::decode_transaction_body::<
403                CalculatorMultiplyResponse,
404                fidl::encoding::DefaultFuchsiaResourceDialect,
405                0x4d6fedd51609fc35,
406            >(_buf?)?;
407            Ok(_response.product)
408        }
409        self.client.send_query_and_decode::<CalculatorMultiplyRequest, f64>(
410            (a, b),
411            0x4d6fedd51609fc35,
412            fidl::encoding::DynamicFlags::empty(),
413            _decode,
414        )
415    }
416
417    type DivideResponseFut =
418        fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect>;
419    fn r#divide(&self, mut dividend: f64, mut divisor: f64) -> Self::DivideResponseFut {
420        fn _decode(
421            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
422        ) -> Result<f64, fidl::Error> {
423            let _response = fidl::client::decode_transaction_body::<
424                CalculatorDivideResponse,
425                fidl::encoding::DefaultFuchsiaResourceDialect,
426                0x4dc343d7222988ba,
427            >(_buf?)?;
428            Ok(_response.quotient)
429        }
430        self.client.send_query_and_decode::<CalculatorDivideRequest, f64>(
431            (dividend, divisor),
432            0x4dc343d7222988ba,
433            fidl::encoding::DynamicFlags::empty(),
434            _decode,
435        )
436    }
437
438    type PowResponseFut =
439        fidl::client::QueryResponseFut<f64, fidl::encoding::DefaultFuchsiaResourceDialect>;
440    fn r#pow(&self, mut base: f64, mut exponent: f64) -> Self::PowResponseFut {
441        fn _decode(
442            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
443        ) -> Result<f64, fidl::Error> {
444            let _response = fidl::client::decode_transaction_body::<
445                CalculatorPowResponse,
446                fidl::encoding::DefaultFuchsiaResourceDialect,
447                0x3467780dee7ba196,
448            >(_buf?)?;
449            Ok(_response.power)
450        }
451        self.client.send_query_and_decode::<CalculatorPowRequest, f64>(
452            (base, exponent),
453            0x3467780dee7ba196,
454            fidl::encoding::DynamicFlags::empty(),
455            _decode,
456        )
457    }
458}
459
460pub struct CalculatorEventStream {
461    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
462}
463
464impl std::marker::Unpin for CalculatorEventStream {}
465
466impl futures::stream::FusedStream for CalculatorEventStream {
467    fn is_terminated(&self) -> bool {
468        self.event_receiver.is_terminated()
469    }
470}
471
472impl futures::Stream for CalculatorEventStream {
473    type Item = Result<CalculatorEvent, fidl::Error>;
474
475    fn poll_next(
476        mut self: std::pin::Pin<&mut Self>,
477        cx: &mut std::task::Context<'_>,
478    ) -> std::task::Poll<Option<Self::Item>> {
479        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
480            &mut self.event_receiver,
481            cx
482        )?) {
483            Some(buf) => std::task::Poll::Ready(Some(CalculatorEvent::decode(buf))),
484            None => std::task::Poll::Ready(None),
485        }
486    }
487}
488
489#[derive(Debug)]
490pub enum CalculatorEvent {}
491
492impl CalculatorEvent {
493    /// Decodes a message buffer as a [`CalculatorEvent`].
494    fn decode(
495        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
496    ) -> Result<CalculatorEvent, fidl::Error> {
497        let (bytes, _handles) = buf.split_mut();
498        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
499        debug_assert_eq!(tx_header.tx_id, 0);
500        match tx_header.ordinal {
501            _ => Err(fidl::Error::UnknownOrdinal {
502                ordinal: tx_header.ordinal,
503                protocol_name: <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
504            }),
505        }
506    }
507}
508
509/// A Stream of incoming requests for fuchsia.examples.calculator/Calculator.
510pub struct CalculatorRequestStream {
511    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
512    is_terminated: bool,
513}
514
515impl std::marker::Unpin for CalculatorRequestStream {}
516
517impl futures::stream::FusedStream for CalculatorRequestStream {
518    fn is_terminated(&self) -> bool {
519        self.is_terminated
520    }
521}
522
523impl fidl::endpoints::RequestStream for CalculatorRequestStream {
524    type Protocol = CalculatorMarker;
525    type ControlHandle = CalculatorControlHandle;
526
527    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
528        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
529    }
530
531    fn control_handle(&self) -> Self::ControlHandle {
532        CalculatorControlHandle { inner: self.inner.clone() }
533    }
534
535    fn into_inner(
536        self,
537    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
538    {
539        (self.inner, self.is_terminated)
540    }
541
542    fn from_inner(
543        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
544        is_terminated: bool,
545    ) -> Self {
546        Self { inner, is_terminated }
547    }
548}
549
550impl futures::Stream for CalculatorRequestStream {
551    type Item = Result<CalculatorRequest, fidl::Error>;
552
553    fn poll_next(
554        mut self: std::pin::Pin<&mut Self>,
555        cx: &mut std::task::Context<'_>,
556    ) -> std::task::Poll<Option<Self::Item>> {
557        let this = &mut *self;
558        if this.inner.check_shutdown(cx) {
559            this.is_terminated = true;
560            return std::task::Poll::Ready(None);
561        }
562        if this.is_terminated {
563            panic!("polled CalculatorRequestStream after completion");
564        }
565        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
566            |bytes, handles| {
567                match this.inner.channel().read_etc(cx, bytes, handles) {
568                    std::task::Poll::Ready(Ok(())) => {}
569                    std::task::Poll::Pending => return std::task::Poll::Pending,
570                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
571                        this.is_terminated = true;
572                        return std::task::Poll::Ready(None);
573                    }
574                    std::task::Poll::Ready(Err(e)) => {
575                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
576                            e.into(),
577                        ))));
578                    }
579                }
580
581                // A message has been received from the channel
582                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
583
584                std::task::Poll::Ready(Some(match header.ordinal {
585                    0x5f2286171d9ff91e => {
586                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
587                        let mut req = fidl::new_empty!(
588                            CalculatorAddRequest,
589                            fidl::encoding::DefaultFuchsiaResourceDialect
590                        );
591                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorAddRequest>(&header, _body_bytes, handles, &mut req)?;
592                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
593                        Ok(CalculatorRequest::Add {
594                            a: req.a,
595                            b: req.b,
596
597                            responder: CalculatorAddResponder {
598                                control_handle: std::mem::ManuallyDrop::new(control_handle),
599                                tx_id: header.tx_id,
600                            },
601                        })
602                    }
603                    0x64ce8ff043420d78 => {
604                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
605                        let mut req = fidl::new_empty!(
606                            CalculatorSubtractRequest,
607                            fidl::encoding::DefaultFuchsiaResourceDialect
608                        );
609                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorSubtractRequest>(&header, _body_bytes, handles, &mut req)?;
610                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
611                        Ok(CalculatorRequest::Subtract {
612                            a: req.a,
613                            b: req.b,
614
615                            responder: CalculatorSubtractResponder {
616                                control_handle: std::mem::ManuallyDrop::new(control_handle),
617                                tx_id: header.tx_id,
618                            },
619                        })
620                    }
621                    0x4d6fedd51609fc35 => {
622                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
623                        let mut req = fidl::new_empty!(
624                            CalculatorMultiplyRequest,
625                            fidl::encoding::DefaultFuchsiaResourceDialect
626                        );
627                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorMultiplyRequest>(&header, _body_bytes, handles, &mut req)?;
628                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
629                        Ok(CalculatorRequest::Multiply {
630                            a: req.a,
631                            b: req.b,
632
633                            responder: CalculatorMultiplyResponder {
634                                control_handle: std::mem::ManuallyDrop::new(control_handle),
635                                tx_id: header.tx_id,
636                            },
637                        })
638                    }
639                    0x4dc343d7222988ba => {
640                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
641                        let mut req = fidl::new_empty!(
642                            CalculatorDivideRequest,
643                            fidl::encoding::DefaultFuchsiaResourceDialect
644                        );
645                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorDivideRequest>(&header, _body_bytes, handles, &mut req)?;
646                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
647                        Ok(CalculatorRequest::Divide {
648                            dividend: req.dividend,
649                            divisor: req.divisor,
650
651                            responder: CalculatorDivideResponder {
652                                control_handle: std::mem::ManuallyDrop::new(control_handle),
653                                tx_id: header.tx_id,
654                            },
655                        })
656                    }
657                    0x3467780dee7ba196 => {
658                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
659                        let mut req = fidl::new_empty!(
660                            CalculatorPowRequest,
661                            fidl::encoding::DefaultFuchsiaResourceDialect
662                        );
663                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorPowRequest>(&header, _body_bytes, handles, &mut req)?;
664                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
665                        Ok(CalculatorRequest::Pow {
666                            base: req.base,
667                            exponent: req.exponent,
668
669                            responder: CalculatorPowResponder {
670                                control_handle: std::mem::ManuallyDrop::new(control_handle),
671                                tx_id: header.tx_id,
672                            },
673                        })
674                    }
675                    _ => Err(fidl::Error::UnknownOrdinal {
676                        ordinal: header.ordinal,
677                        protocol_name:
678                            <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
679                    }),
680                }))
681            },
682        )
683    }
684}
685
686/// A protocol for a simple calculator.
687///
688/// Supports the following operations:
689/// + [`fuchsia.examples.calculator/Calculator.Add`]
690/// + [`fuchsia.examples.calculator/Calculator.Subtract`]
691/// + [`fuchsia.examples.calculator/Calculator.Multiply`]
692/// + [`fuchsia.examples.calculator/Calculator.Divide`]
693/// + [`fuchsia.examples.calculator/Calculator.Pow`]
694#[derive(Debug)]
695pub enum CalculatorRequest {
696    /// Adds two numbers together and returns their `sum`.
697    ///
698    /// For example, with `a` being 4.5 and `b` being 3.2, the response `sum` is
699    /// 7.7.
700    ///
701    /// + request `a` the first number to be added.
702    /// + request `b` the second number to be added.
703    /// - response `sum` the sum of a and b.
704    Add { a: f64, b: f64, responder: CalculatorAddResponder },
705    /// Subtracts two numbers and returns their `difference`.
706    ///
707    /// For example, with `a` being 7.7 and `b` being 3.2, the response
708    /// `difference` is 4.5
709    ///
710    /// + request `a` the number to be subracted _from_.
711    /// + request `b` the number to subtract.
712    /// - response `difference` the difference between `a` and `b`.
713    Subtract { a: f64, b: f64, responder: CalculatorSubtractResponder },
714    /// Multiplies two numbers and returns their `product`.
715    ///
716    /// For example, with `a` being 1.5 and `b` being 2.0, the response
717    /// `product` is 3.0
718    ///
719    /// + request `a` the first number used to calculatorulate the `product`.
720    /// + request `b` the second number used to calculatorulate the `product`.
721    /// - response `product` the result of multiplying `a` and `b`.
722    Multiply { a: f64, b: f64, responder: CalculatorMultiplyResponder },
723    /// Divides one number by another and return the `quotient`.
724    ///
725    /// For example with a `dividend` of 2.0 and a `divisor` of 4.0, the
726    /// response `quotient` is 0.5.
727    ///
728    /// + request `dividend` the number to divide with.
729    /// + request `divisor` the number to divide into.
730    /// - response `quotient` the result of dividing the `dividend` into the `divisor`.
731    Divide { dividend: f64, divisor: f64, responder: CalculatorDivideResponder },
732    /// Takes `base` to the `exponent` and returns the `power`.
733    ///
734    /// For example with a `base` of 3.0 and an `exponent` of 4.0, the response
735    /// `power` is 81.0.
736    ///
737    /// + request `base` the number to multiply by itself.
738    /// + request `exponent` the number of times to successively multiply
739    /// `base`.
740    /// - response `power` the result of multiplying `base` by itself `exponent`
741    /// times..
742    Pow { base: f64, exponent: f64, responder: CalculatorPowResponder },
743}
744
745impl CalculatorRequest {
746    #[allow(irrefutable_let_patterns)]
747    pub fn into_add(self) -> Option<(f64, f64, CalculatorAddResponder)> {
748        if let CalculatorRequest::Add { a, b, responder } = self {
749            Some((a, b, responder))
750        } else {
751            None
752        }
753    }
754
755    #[allow(irrefutable_let_patterns)]
756    pub fn into_subtract(self) -> Option<(f64, f64, CalculatorSubtractResponder)> {
757        if let CalculatorRequest::Subtract { a, b, responder } = self {
758            Some((a, b, responder))
759        } else {
760            None
761        }
762    }
763
764    #[allow(irrefutable_let_patterns)]
765    pub fn into_multiply(self) -> Option<(f64, f64, CalculatorMultiplyResponder)> {
766        if let CalculatorRequest::Multiply { a, b, responder } = self {
767            Some((a, b, responder))
768        } else {
769            None
770        }
771    }
772
773    #[allow(irrefutable_let_patterns)]
774    pub fn into_divide(self) -> Option<(f64, f64, CalculatorDivideResponder)> {
775        if let CalculatorRequest::Divide { dividend, divisor, responder } = self {
776            Some((dividend, divisor, responder))
777        } else {
778            None
779        }
780    }
781
782    #[allow(irrefutable_let_patterns)]
783    pub fn into_pow(self) -> Option<(f64, f64, CalculatorPowResponder)> {
784        if let CalculatorRequest::Pow { base, exponent, responder } = self {
785            Some((base, exponent, responder))
786        } else {
787            None
788        }
789    }
790
791    /// Name of the method defined in FIDL
792    pub fn method_name(&self) -> &'static str {
793        match *self {
794            CalculatorRequest::Add { .. } => "add",
795            CalculatorRequest::Subtract { .. } => "subtract",
796            CalculatorRequest::Multiply { .. } => "multiply",
797            CalculatorRequest::Divide { .. } => "divide",
798            CalculatorRequest::Pow { .. } => "pow",
799        }
800    }
801}
802
803#[derive(Debug, Clone)]
804pub struct CalculatorControlHandle {
805    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
806}
807
808impl fidl::endpoints::ControlHandle for CalculatorControlHandle {
809    fn shutdown(&self) {
810        self.inner.shutdown()
811    }
812
813    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
814        self.inner.shutdown_with_epitaph(status)
815    }
816
817    fn is_closed(&self) -> bool {
818        self.inner.channel().is_closed()
819    }
820    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
821        self.inner.channel().on_closed()
822    }
823
824    #[cfg(target_os = "fuchsia")]
825    fn signal_peer(
826        &self,
827        clear_mask: zx::Signals,
828        set_mask: zx::Signals,
829    ) -> Result<(), zx_status::Status> {
830        use fidl::Peered;
831        self.inner.channel().signal_peer(clear_mask, set_mask)
832    }
833}
834
835impl CalculatorControlHandle {}
836
837#[must_use = "FIDL methods require a response to be sent"]
838#[derive(Debug)]
839pub struct CalculatorAddResponder {
840    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
841    tx_id: u32,
842}
843
844/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
845/// if the responder is dropped without sending a response, so that the client
846/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
847impl std::ops::Drop for CalculatorAddResponder {
848    fn drop(&mut self) {
849        self.control_handle.shutdown();
850        // Safety: drops once, never accessed again
851        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
852    }
853}
854
855impl fidl::endpoints::Responder for CalculatorAddResponder {
856    type ControlHandle = CalculatorControlHandle;
857
858    fn control_handle(&self) -> &CalculatorControlHandle {
859        &self.control_handle
860    }
861
862    fn drop_without_shutdown(mut self) {
863        // Safety: drops once, never accessed again due to mem::forget
864        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
865        // Prevent Drop from running (which would shut down the channel)
866        std::mem::forget(self);
867    }
868}
869
870impl CalculatorAddResponder {
871    /// Sends a response to the FIDL transaction.
872    ///
873    /// Sets the channel to shutdown if an error occurs.
874    pub fn send(self, mut sum: f64) -> Result<(), fidl::Error> {
875        let _result = self.send_raw(sum);
876        if _result.is_err() {
877            self.control_handle.shutdown();
878        }
879        self.drop_without_shutdown();
880        _result
881    }
882
883    /// Similar to "send" but does not shutdown the channel if an error occurs.
884    pub fn send_no_shutdown_on_err(self, mut sum: f64) -> Result<(), fidl::Error> {
885        let _result = self.send_raw(sum);
886        self.drop_without_shutdown();
887        _result
888    }
889
890    fn send_raw(&self, mut sum: f64) -> Result<(), fidl::Error> {
891        self.control_handle.inner.send::<CalculatorAddResponse>(
892            (sum,),
893            self.tx_id,
894            0x5f2286171d9ff91e,
895            fidl::encoding::DynamicFlags::empty(),
896        )
897    }
898}
899
900#[must_use = "FIDL methods require a response to be sent"]
901#[derive(Debug)]
902pub struct CalculatorSubtractResponder {
903    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
904    tx_id: u32,
905}
906
907/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
908/// if the responder is dropped without sending a response, so that the client
909/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
910impl std::ops::Drop for CalculatorSubtractResponder {
911    fn drop(&mut self) {
912        self.control_handle.shutdown();
913        // Safety: drops once, never accessed again
914        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
915    }
916}
917
918impl fidl::endpoints::Responder for CalculatorSubtractResponder {
919    type ControlHandle = CalculatorControlHandle;
920
921    fn control_handle(&self) -> &CalculatorControlHandle {
922        &self.control_handle
923    }
924
925    fn drop_without_shutdown(mut self) {
926        // Safety: drops once, never accessed again due to mem::forget
927        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
928        // Prevent Drop from running (which would shut down the channel)
929        std::mem::forget(self);
930    }
931}
932
933impl CalculatorSubtractResponder {
934    /// Sends a response to the FIDL transaction.
935    ///
936    /// Sets the channel to shutdown if an error occurs.
937    pub fn send(self, mut difference: f64) -> Result<(), fidl::Error> {
938        let _result = self.send_raw(difference);
939        if _result.is_err() {
940            self.control_handle.shutdown();
941        }
942        self.drop_without_shutdown();
943        _result
944    }
945
946    /// Similar to "send" but does not shutdown the channel if an error occurs.
947    pub fn send_no_shutdown_on_err(self, mut difference: f64) -> Result<(), fidl::Error> {
948        let _result = self.send_raw(difference);
949        self.drop_without_shutdown();
950        _result
951    }
952
953    fn send_raw(&self, mut difference: f64) -> Result<(), fidl::Error> {
954        self.control_handle.inner.send::<CalculatorSubtractResponse>(
955            (difference,),
956            self.tx_id,
957            0x64ce8ff043420d78,
958            fidl::encoding::DynamicFlags::empty(),
959        )
960    }
961}
962
963#[must_use = "FIDL methods require a response to be sent"]
964#[derive(Debug)]
965pub struct CalculatorMultiplyResponder {
966    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
967    tx_id: u32,
968}
969
970/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
971/// if the responder is dropped without sending a response, so that the client
972/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
973impl std::ops::Drop for CalculatorMultiplyResponder {
974    fn drop(&mut self) {
975        self.control_handle.shutdown();
976        // Safety: drops once, never accessed again
977        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
978    }
979}
980
981impl fidl::endpoints::Responder for CalculatorMultiplyResponder {
982    type ControlHandle = CalculatorControlHandle;
983
984    fn control_handle(&self) -> &CalculatorControlHandle {
985        &self.control_handle
986    }
987
988    fn drop_without_shutdown(mut self) {
989        // Safety: drops once, never accessed again due to mem::forget
990        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
991        // Prevent Drop from running (which would shut down the channel)
992        std::mem::forget(self);
993    }
994}
995
996impl CalculatorMultiplyResponder {
997    /// Sends a response to the FIDL transaction.
998    ///
999    /// Sets the channel to shutdown if an error occurs.
1000    pub fn send(self, mut product: f64) -> Result<(), fidl::Error> {
1001        let _result = self.send_raw(product);
1002        if _result.is_err() {
1003            self.control_handle.shutdown();
1004        }
1005        self.drop_without_shutdown();
1006        _result
1007    }
1008
1009    /// Similar to "send" but does not shutdown the channel if an error occurs.
1010    pub fn send_no_shutdown_on_err(self, mut product: f64) -> Result<(), fidl::Error> {
1011        let _result = self.send_raw(product);
1012        self.drop_without_shutdown();
1013        _result
1014    }
1015
1016    fn send_raw(&self, mut product: f64) -> Result<(), fidl::Error> {
1017        self.control_handle.inner.send::<CalculatorMultiplyResponse>(
1018            (product,),
1019            self.tx_id,
1020            0x4d6fedd51609fc35,
1021            fidl::encoding::DynamicFlags::empty(),
1022        )
1023    }
1024}
1025
1026#[must_use = "FIDL methods require a response to be sent"]
1027#[derive(Debug)]
1028pub struct CalculatorDivideResponder {
1029    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
1030    tx_id: u32,
1031}
1032
1033/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
1034/// if the responder is dropped without sending a response, so that the client
1035/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1036impl std::ops::Drop for CalculatorDivideResponder {
1037    fn drop(&mut self) {
1038        self.control_handle.shutdown();
1039        // Safety: drops once, never accessed again
1040        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1041    }
1042}
1043
1044impl fidl::endpoints::Responder for CalculatorDivideResponder {
1045    type ControlHandle = CalculatorControlHandle;
1046
1047    fn control_handle(&self) -> &CalculatorControlHandle {
1048        &self.control_handle
1049    }
1050
1051    fn drop_without_shutdown(mut self) {
1052        // Safety: drops once, never accessed again due to mem::forget
1053        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1054        // Prevent Drop from running (which would shut down the channel)
1055        std::mem::forget(self);
1056    }
1057}
1058
1059impl CalculatorDivideResponder {
1060    /// Sends a response to the FIDL transaction.
1061    ///
1062    /// Sets the channel to shutdown if an error occurs.
1063    pub fn send(self, mut quotient: f64) -> Result<(), fidl::Error> {
1064        let _result = self.send_raw(quotient);
1065        if _result.is_err() {
1066            self.control_handle.shutdown();
1067        }
1068        self.drop_without_shutdown();
1069        _result
1070    }
1071
1072    /// Similar to "send" but does not shutdown the channel if an error occurs.
1073    pub fn send_no_shutdown_on_err(self, mut quotient: f64) -> Result<(), fidl::Error> {
1074        let _result = self.send_raw(quotient);
1075        self.drop_without_shutdown();
1076        _result
1077    }
1078
1079    fn send_raw(&self, mut quotient: f64) -> Result<(), fidl::Error> {
1080        self.control_handle.inner.send::<CalculatorDivideResponse>(
1081            (quotient,),
1082            self.tx_id,
1083            0x4dc343d7222988ba,
1084            fidl::encoding::DynamicFlags::empty(),
1085        )
1086    }
1087}
1088
1089#[must_use = "FIDL methods require a response to be sent"]
1090#[derive(Debug)]
1091pub struct CalculatorPowResponder {
1092    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
1093    tx_id: u32,
1094}
1095
1096/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
1097/// if the responder is dropped without sending a response, so that the client
1098/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1099impl std::ops::Drop for CalculatorPowResponder {
1100    fn drop(&mut self) {
1101        self.control_handle.shutdown();
1102        // Safety: drops once, never accessed again
1103        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1104    }
1105}
1106
1107impl fidl::endpoints::Responder for CalculatorPowResponder {
1108    type ControlHandle = CalculatorControlHandle;
1109
1110    fn control_handle(&self) -> &CalculatorControlHandle {
1111        &self.control_handle
1112    }
1113
1114    fn drop_without_shutdown(mut self) {
1115        // Safety: drops once, never accessed again due to mem::forget
1116        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1117        // Prevent Drop from running (which would shut down the channel)
1118        std::mem::forget(self);
1119    }
1120}
1121
1122impl CalculatorPowResponder {
1123    /// Sends a response to the FIDL transaction.
1124    ///
1125    /// Sets the channel to shutdown if an error occurs.
1126    pub fn send(self, mut power: f64) -> Result<(), fidl::Error> {
1127        let _result = self.send_raw(power);
1128        if _result.is_err() {
1129            self.control_handle.shutdown();
1130        }
1131        self.drop_without_shutdown();
1132        _result
1133    }
1134
1135    /// Similar to "send" but does not shutdown the channel if an error occurs.
1136    pub fn send_no_shutdown_on_err(self, mut power: f64) -> Result<(), fidl::Error> {
1137        let _result = self.send_raw(power);
1138        self.drop_without_shutdown();
1139        _result
1140    }
1141
1142    fn send_raw(&self, mut power: f64) -> Result<(), fidl::Error> {
1143        self.control_handle.inner.send::<CalculatorPowResponse>(
1144            (power,),
1145            self.tx_id,
1146            0x3467780dee7ba196,
1147            fidl::encoding::DynamicFlags::empty(),
1148        )
1149    }
1150}
1151
1152mod internal {
1153    use super::*;
1154}