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 CalculatorControlHandle {
809    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
810        self.inner.shutdown_with_epitaph(status.into())
811    }
812}
813
814impl fidl::endpoints::ControlHandle for CalculatorControlHandle {
815    fn shutdown(&self) {
816        self.inner.shutdown()
817    }
818
819    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
820        self.inner.shutdown_with_epitaph(status)
821    }
822
823    fn is_closed(&self) -> bool {
824        self.inner.channel().is_closed()
825    }
826    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
827        self.inner.channel().on_closed()
828    }
829
830    #[cfg(target_os = "fuchsia")]
831    fn signal_peer(
832        &self,
833        clear_mask: zx::Signals,
834        set_mask: zx::Signals,
835    ) -> Result<(), zx_status::Status> {
836        use fidl::Peered;
837        self.inner.channel().signal_peer(clear_mask, set_mask)
838    }
839}
840
841impl CalculatorControlHandle {}
842
843#[must_use = "FIDL methods require a response to be sent"]
844#[derive(Debug)]
845pub struct CalculatorAddResponder {
846    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
847    tx_id: u32,
848}
849
850/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
851/// if the responder is dropped without sending a response, so that the client
852/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
853impl std::ops::Drop for CalculatorAddResponder {
854    fn drop(&mut self) {
855        self.control_handle.shutdown();
856        // Safety: drops once, never accessed again
857        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
858    }
859}
860
861impl fidl::endpoints::Responder for CalculatorAddResponder {
862    type ControlHandle = CalculatorControlHandle;
863
864    fn control_handle(&self) -> &CalculatorControlHandle {
865        &self.control_handle
866    }
867
868    fn drop_without_shutdown(mut self) {
869        // Safety: drops once, never accessed again due to mem::forget
870        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
871        // Prevent Drop from running (which would shut down the channel)
872        std::mem::forget(self);
873    }
874}
875
876impl CalculatorAddResponder {
877    /// Sends a response to the FIDL transaction.
878    ///
879    /// Sets the channel to shutdown if an error occurs.
880    pub fn send(self, mut sum: f64) -> Result<(), fidl::Error> {
881        let _result = self.send_raw(sum);
882        if _result.is_err() {
883            self.control_handle.shutdown();
884        }
885        self.drop_without_shutdown();
886        _result
887    }
888
889    /// Similar to "send" but does not shutdown the channel if an error occurs.
890    pub fn send_no_shutdown_on_err(self, mut sum: f64) -> Result<(), fidl::Error> {
891        let _result = self.send_raw(sum);
892        self.drop_without_shutdown();
893        _result
894    }
895
896    fn send_raw(&self, mut sum: f64) -> Result<(), fidl::Error> {
897        self.control_handle.inner.send::<CalculatorAddResponse>(
898            (sum,),
899            self.tx_id,
900            0x5f2286171d9ff91e,
901            fidl::encoding::DynamicFlags::empty(),
902        )
903    }
904}
905
906#[must_use = "FIDL methods require a response to be sent"]
907#[derive(Debug)]
908pub struct CalculatorSubtractResponder {
909    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
910    tx_id: u32,
911}
912
913/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
914/// if the responder is dropped without sending a response, so that the client
915/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
916impl std::ops::Drop for CalculatorSubtractResponder {
917    fn drop(&mut self) {
918        self.control_handle.shutdown();
919        // Safety: drops once, never accessed again
920        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
921    }
922}
923
924impl fidl::endpoints::Responder for CalculatorSubtractResponder {
925    type ControlHandle = CalculatorControlHandle;
926
927    fn control_handle(&self) -> &CalculatorControlHandle {
928        &self.control_handle
929    }
930
931    fn drop_without_shutdown(mut self) {
932        // Safety: drops once, never accessed again due to mem::forget
933        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
934        // Prevent Drop from running (which would shut down the channel)
935        std::mem::forget(self);
936    }
937}
938
939impl CalculatorSubtractResponder {
940    /// Sends a response to the FIDL transaction.
941    ///
942    /// Sets the channel to shutdown if an error occurs.
943    pub fn send(self, mut difference: f64) -> Result<(), fidl::Error> {
944        let _result = self.send_raw(difference);
945        if _result.is_err() {
946            self.control_handle.shutdown();
947        }
948        self.drop_without_shutdown();
949        _result
950    }
951
952    /// Similar to "send" but does not shutdown the channel if an error occurs.
953    pub fn send_no_shutdown_on_err(self, mut difference: f64) -> Result<(), fidl::Error> {
954        let _result = self.send_raw(difference);
955        self.drop_without_shutdown();
956        _result
957    }
958
959    fn send_raw(&self, mut difference: f64) -> Result<(), fidl::Error> {
960        self.control_handle.inner.send::<CalculatorSubtractResponse>(
961            (difference,),
962            self.tx_id,
963            0x64ce8ff043420d78,
964            fidl::encoding::DynamicFlags::empty(),
965        )
966    }
967}
968
969#[must_use = "FIDL methods require a response to be sent"]
970#[derive(Debug)]
971pub struct CalculatorMultiplyResponder {
972    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
973    tx_id: u32,
974}
975
976/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
977/// if the responder is dropped without sending a response, so that the client
978/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
979impl std::ops::Drop for CalculatorMultiplyResponder {
980    fn drop(&mut self) {
981        self.control_handle.shutdown();
982        // Safety: drops once, never accessed again
983        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
984    }
985}
986
987impl fidl::endpoints::Responder for CalculatorMultiplyResponder {
988    type ControlHandle = CalculatorControlHandle;
989
990    fn control_handle(&self) -> &CalculatorControlHandle {
991        &self.control_handle
992    }
993
994    fn drop_without_shutdown(mut self) {
995        // Safety: drops once, never accessed again due to mem::forget
996        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
997        // Prevent Drop from running (which would shut down the channel)
998        std::mem::forget(self);
999    }
1000}
1001
1002impl CalculatorMultiplyResponder {
1003    /// Sends a response to the FIDL transaction.
1004    ///
1005    /// Sets the channel to shutdown if an error occurs.
1006    pub fn send(self, mut product: f64) -> Result<(), fidl::Error> {
1007        let _result = self.send_raw(product);
1008        if _result.is_err() {
1009            self.control_handle.shutdown();
1010        }
1011        self.drop_without_shutdown();
1012        _result
1013    }
1014
1015    /// Similar to "send" but does not shutdown the channel if an error occurs.
1016    pub fn send_no_shutdown_on_err(self, mut product: f64) -> Result<(), fidl::Error> {
1017        let _result = self.send_raw(product);
1018        self.drop_without_shutdown();
1019        _result
1020    }
1021
1022    fn send_raw(&self, mut product: f64) -> Result<(), fidl::Error> {
1023        self.control_handle.inner.send::<CalculatorMultiplyResponse>(
1024            (product,),
1025            self.tx_id,
1026            0x4d6fedd51609fc35,
1027            fidl::encoding::DynamicFlags::empty(),
1028        )
1029    }
1030}
1031
1032#[must_use = "FIDL methods require a response to be sent"]
1033#[derive(Debug)]
1034pub struct CalculatorDivideResponder {
1035    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
1036    tx_id: u32,
1037}
1038
1039/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
1040/// if the responder is dropped without sending a response, so that the client
1041/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1042impl std::ops::Drop for CalculatorDivideResponder {
1043    fn drop(&mut self) {
1044        self.control_handle.shutdown();
1045        // Safety: drops once, never accessed again
1046        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1047    }
1048}
1049
1050impl fidl::endpoints::Responder for CalculatorDivideResponder {
1051    type ControlHandle = CalculatorControlHandle;
1052
1053    fn control_handle(&self) -> &CalculatorControlHandle {
1054        &self.control_handle
1055    }
1056
1057    fn drop_without_shutdown(mut self) {
1058        // Safety: drops once, never accessed again due to mem::forget
1059        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1060        // Prevent Drop from running (which would shut down the channel)
1061        std::mem::forget(self);
1062    }
1063}
1064
1065impl CalculatorDivideResponder {
1066    /// Sends a response to the FIDL transaction.
1067    ///
1068    /// Sets the channel to shutdown if an error occurs.
1069    pub fn send(self, mut quotient: f64) -> Result<(), fidl::Error> {
1070        let _result = self.send_raw(quotient);
1071        if _result.is_err() {
1072            self.control_handle.shutdown();
1073        }
1074        self.drop_without_shutdown();
1075        _result
1076    }
1077
1078    /// Similar to "send" but does not shutdown the channel if an error occurs.
1079    pub fn send_no_shutdown_on_err(self, mut quotient: f64) -> Result<(), fidl::Error> {
1080        let _result = self.send_raw(quotient);
1081        self.drop_without_shutdown();
1082        _result
1083    }
1084
1085    fn send_raw(&self, mut quotient: f64) -> Result<(), fidl::Error> {
1086        self.control_handle.inner.send::<CalculatorDivideResponse>(
1087            (quotient,),
1088            self.tx_id,
1089            0x4dc343d7222988ba,
1090            fidl::encoding::DynamicFlags::empty(),
1091        )
1092    }
1093}
1094
1095#[must_use = "FIDL methods require a response to be sent"]
1096#[derive(Debug)]
1097pub struct CalculatorPowResponder {
1098    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
1099    tx_id: u32,
1100}
1101
1102/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
1103/// if the responder is dropped without sending a response, so that the client
1104/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1105impl std::ops::Drop for CalculatorPowResponder {
1106    fn drop(&mut self) {
1107        self.control_handle.shutdown();
1108        // Safety: drops once, never accessed again
1109        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1110    }
1111}
1112
1113impl fidl::endpoints::Responder for CalculatorPowResponder {
1114    type ControlHandle = CalculatorControlHandle;
1115
1116    fn control_handle(&self) -> &CalculatorControlHandle {
1117        &self.control_handle
1118    }
1119
1120    fn drop_without_shutdown(mut self) {
1121        // Safety: drops once, never accessed again due to mem::forget
1122        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1123        // Prevent Drop from running (which would shut down the channel)
1124        std::mem::forget(self);
1125    }
1126}
1127
1128impl CalculatorPowResponder {
1129    /// Sends a response to the FIDL transaction.
1130    ///
1131    /// Sets the channel to shutdown if an error occurs.
1132    pub fn send(self, mut power: f64) -> Result<(), fidl::Error> {
1133        let _result = self.send_raw(power);
1134        if _result.is_err() {
1135            self.control_handle.shutdown();
1136        }
1137        self.drop_without_shutdown();
1138        _result
1139    }
1140
1141    /// Similar to "send" but does not shutdown the channel if an error occurs.
1142    pub fn send_no_shutdown_on_err(self, mut power: f64) -> Result<(), fidl::Error> {
1143        let _result = self.send_raw(power);
1144        self.drop_without_shutdown();
1145        _result
1146    }
1147
1148    fn send_raw(&self, mut power: f64) -> Result<(), fidl::Error> {
1149        self.control_handle.inner.send::<CalculatorPowResponse>(
1150            (power,),
1151            self.tx_id,
1152            0x3467780dee7ba196,
1153            fidl::encoding::DynamicFlags::empty(),
1154        )
1155    }
1156}
1157
1158mod internal {
1159    use super::*;
1160}