fidl_examples_calculator/
fidl_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_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 = "(anonymous) Calculator";
24}
25pub type CalculatorDivideResult = Result<(i32, i32), DivisionError>;
26
27pub trait CalculatorProxyInterface: Send + Sync {
28    type AddResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
29    fn r#add(&self, a: i32, b: i32) -> Self::AddResponseFut;
30    type DivideResponseFut: std::future::Future<Output = Result<CalculatorDivideResult, fidl::Error>>
31        + Send;
32    fn r#divide(&self, dividend: i32, divisor: i32) -> Self::DivideResponseFut;
33    fn r#clear(&self) -> Result<(), fidl::Error>;
34}
35#[derive(Debug)]
36#[cfg(target_os = "fuchsia")]
37pub struct CalculatorSynchronousProxy {
38    client: fidl::client::sync::Client,
39}
40
41#[cfg(target_os = "fuchsia")]
42impl fidl::endpoints::SynchronousProxy for CalculatorSynchronousProxy {
43    type Proxy = CalculatorProxy;
44    type Protocol = CalculatorMarker;
45
46    fn from_channel(inner: fidl::Channel) -> Self {
47        Self::new(inner)
48    }
49
50    fn into_channel(self) -> fidl::Channel {
51        self.client.into_channel()
52    }
53
54    fn as_channel(&self) -> &fidl::Channel {
55        self.client.as_channel()
56    }
57}
58
59#[cfg(target_os = "fuchsia")]
60impl CalculatorSynchronousProxy {
61    pub fn new(channel: fidl::Channel) -> Self {
62        let protocol_name = <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
63        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
64    }
65
66    pub fn into_channel(self) -> fidl::Channel {
67        self.client.into_channel()
68    }
69
70    /// Waits until an event arrives and returns it. It is safe for other
71    /// threads to make concurrent requests while waiting for an event.
72    pub fn wait_for_event(
73        &self,
74        deadline: zx::MonotonicInstant,
75    ) -> Result<CalculatorEvent, fidl::Error> {
76        CalculatorEvent::decode(self.client.wait_for_event(deadline)?)
77    }
78
79    pub fn r#add(
80        &self,
81        mut a: i32,
82        mut b: i32,
83        ___deadline: zx::MonotonicInstant,
84    ) -> Result<i32, fidl::Error> {
85        let _response = self.client.send_query::<
86            CalculatorAddRequest,
87            fidl::encoding::FlexibleType<CalculatorAddResponse>,
88        >(
89            (a, b,),
90            0x77e89989c55e6e01,
91            fidl::encoding::DynamicFlags::FLEXIBLE,
92            ___deadline,
93        )?
94        .into_result::<CalculatorMarker>("add")?;
95        Ok(_response.sum)
96    }
97
98    pub fn r#divide(
99        &self,
100        mut dividend: i32,
101        mut divisor: i32,
102        ___deadline: zx::MonotonicInstant,
103    ) -> Result<CalculatorDivideResult, fidl::Error> {
104        let _response = self.client.send_query::<
105            CalculatorDivideRequest,
106            fidl::encoding::FlexibleResultType<CalculatorDivideResponse, DivisionError>,
107        >(
108            (dividend, divisor,),
109            0x4c4ca20ded067af7,
110            fidl::encoding::DynamicFlags::FLEXIBLE,
111            ___deadline,
112        )?
113        .into_result::<CalculatorMarker>("divide")?;
114        Ok(_response.map(|x| (x.quotient, x.remainder)))
115    }
116
117    pub fn r#clear(&self) -> Result<(), fidl::Error> {
118        self.client.send::<fidl::encoding::EmptyPayload>(
119            (),
120            0x673e190d87949c89,
121            fidl::encoding::DynamicFlags::FLEXIBLE,
122        )
123    }
124}
125
126#[cfg(target_os = "fuchsia")]
127impl From<CalculatorSynchronousProxy> for zx::Handle {
128    fn from(value: CalculatorSynchronousProxy) -> Self {
129        value.into_channel().into()
130    }
131}
132
133#[cfg(target_os = "fuchsia")]
134impl From<fidl::Channel> for CalculatorSynchronousProxy {
135    fn from(value: fidl::Channel) -> Self {
136        Self::new(value)
137    }
138}
139
140#[cfg(target_os = "fuchsia")]
141impl fidl::endpoints::FromClient for CalculatorSynchronousProxy {
142    type Protocol = CalculatorMarker;
143
144    fn from_client(value: fidl::endpoints::ClientEnd<CalculatorMarker>) -> Self {
145        Self::new(value.into_channel())
146    }
147}
148
149#[derive(Debug, Clone)]
150pub struct CalculatorProxy {
151    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
152}
153
154impl fidl::endpoints::Proxy for CalculatorProxy {
155    type Protocol = CalculatorMarker;
156
157    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
158        Self::new(inner)
159    }
160
161    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
162        self.client.into_channel().map_err(|client| Self { client })
163    }
164
165    fn as_channel(&self) -> &::fidl::AsyncChannel {
166        self.client.as_channel()
167    }
168}
169
170impl CalculatorProxy {
171    /// Create a new Proxy for examples.calculator/Calculator.
172    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
173        let protocol_name = <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
174        Self { client: fidl::client::Client::new(channel, protocol_name) }
175    }
176
177    /// Get a Stream of events from the remote end of the protocol.
178    ///
179    /// # Panics
180    ///
181    /// Panics if the event stream was already taken.
182    pub fn take_event_stream(&self) -> CalculatorEventStream {
183        CalculatorEventStream { event_receiver: self.client.take_event_receiver() }
184    }
185
186    pub fn r#add(
187        &self,
188        mut a: i32,
189        mut b: i32,
190    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
191        CalculatorProxyInterface::r#add(self, a, b)
192    }
193
194    pub fn r#divide(
195        &self,
196        mut dividend: i32,
197        mut divisor: i32,
198    ) -> fidl::client::QueryResponseFut<
199        CalculatorDivideResult,
200        fidl::encoding::DefaultFuchsiaResourceDialect,
201    > {
202        CalculatorProxyInterface::r#divide(self, dividend, divisor)
203    }
204
205    pub fn r#clear(&self) -> Result<(), fidl::Error> {
206        CalculatorProxyInterface::r#clear(self)
207    }
208}
209
210impl CalculatorProxyInterface for CalculatorProxy {
211    type AddResponseFut =
212        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
213    fn r#add(&self, mut a: i32, mut b: i32) -> Self::AddResponseFut {
214        fn _decode(
215            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
216        ) -> Result<i32, fidl::Error> {
217            let _response = fidl::client::decode_transaction_body::<
218                fidl::encoding::FlexibleType<CalculatorAddResponse>,
219                fidl::encoding::DefaultFuchsiaResourceDialect,
220                0x77e89989c55e6e01,
221            >(_buf?)?
222            .into_result::<CalculatorMarker>("add")?;
223            Ok(_response.sum)
224        }
225        self.client.send_query_and_decode::<CalculatorAddRequest, i32>(
226            (a, b),
227            0x77e89989c55e6e01,
228            fidl::encoding::DynamicFlags::FLEXIBLE,
229            _decode,
230        )
231    }
232
233    type DivideResponseFut = fidl::client::QueryResponseFut<
234        CalculatorDivideResult,
235        fidl::encoding::DefaultFuchsiaResourceDialect,
236    >;
237    fn r#divide(&self, mut dividend: i32, mut divisor: i32) -> Self::DivideResponseFut {
238        fn _decode(
239            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
240        ) -> Result<CalculatorDivideResult, fidl::Error> {
241            let _response = fidl::client::decode_transaction_body::<
242                fidl::encoding::FlexibleResultType<CalculatorDivideResponse, DivisionError>,
243                fidl::encoding::DefaultFuchsiaResourceDialect,
244                0x4c4ca20ded067af7,
245            >(_buf?)?
246            .into_result::<CalculatorMarker>("divide")?;
247            Ok(_response.map(|x| (x.quotient, x.remainder)))
248        }
249        self.client.send_query_and_decode::<CalculatorDivideRequest, CalculatorDivideResult>(
250            (dividend, divisor),
251            0x4c4ca20ded067af7,
252            fidl::encoding::DynamicFlags::FLEXIBLE,
253            _decode,
254        )
255    }
256
257    fn r#clear(&self) -> Result<(), fidl::Error> {
258        self.client.send::<fidl::encoding::EmptyPayload>(
259            (),
260            0x673e190d87949c89,
261            fidl::encoding::DynamicFlags::FLEXIBLE,
262        )
263    }
264}
265
266pub struct CalculatorEventStream {
267    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
268}
269
270impl std::marker::Unpin for CalculatorEventStream {}
271
272impl futures::stream::FusedStream for CalculatorEventStream {
273    fn is_terminated(&self) -> bool {
274        self.event_receiver.is_terminated()
275    }
276}
277
278impl futures::Stream for CalculatorEventStream {
279    type Item = Result<CalculatorEvent, fidl::Error>;
280
281    fn poll_next(
282        mut self: std::pin::Pin<&mut Self>,
283        cx: &mut std::task::Context<'_>,
284    ) -> std::task::Poll<Option<Self::Item>> {
285        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
286            &mut self.event_receiver,
287            cx
288        )?) {
289            Some(buf) => std::task::Poll::Ready(Some(CalculatorEvent::decode(buf))),
290            None => std::task::Poll::Ready(None),
291        }
292    }
293}
294
295#[derive(Debug)]
296pub enum CalculatorEvent {
297    OnError {
298        status_code: u32,
299    },
300    #[non_exhaustive]
301    _UnknownEvent {
302        /// Ordinal of the event that was sent.
303        ordinal: u64,
304    },
305}
306
307impl CalculatorEvent {
308    #[allow(irrefutable_let_patterns)]
309    pub fn into_on_error(self) -> Option<u32> {
310        if let CalculatorEvent::OnError { status_code } = self {
311            Some((status_code))
312        } else {
313            None
314        }
315    }
316
317    /// Decodes a message buffer as a [`CalculatorEvent`].
318    fn decode(
319        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
320    ) -> Result<CalculatorEvent, fidl::Error> {
321        let (bytes, _handles) = buf.split_mut();
322        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
323        debug_assert_eq!(tx_header.tx_id, 0);
324        match tx_header.ordinal {
325            0x7c1350cc0144d3fc => {
326                let mut out = fidl::new_empty!(
327                    CalculatorOnErrorRequest,
328                    fidl::encoding::DefaultFuchsiaResourceDialect
329                );
330                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorOnErrorRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
331                Ok((CalculatorEvent::OnError { status_code: out.status_code }))
332            }
333            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
334                Ok(CalculatorEvent::_UnknownEvent { ordinal: tx_header.ordinal })
335            }
336            _ => Err(fidl::Error::UnknownOrdinal {
337                ordinal: tx_header.ordinal,
338                protocol_name: <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
339            }),
340        }
341    }
342}
343
344/// A Stream of incoming requests for examples.calculator/Calculator.
345pub struct CalculatorRequestStream {
346    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
347    is_terminated: bool,
348}
349
350impl std::marker::Unpin for CalculatorRequestStream {}
351
352impl futures::stream::FusedStream for CalculatorRequestStream {
353    fn is_terminated(&self) -> bool {
354        self.is_terminated
355    }
356}
357
358impl fidl::endpoints::RequestStream for CalculatorRequestStream {
359    type Protocol = CalculatorMarker;
360    type ControlHandle = CalculatorControlHandle;
361
362    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
363        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
364    }
365
366    fn control_handle(&self) -> Self::ControlHandle {
367        CalculatorControlHandle { inner: self.inner.clone() }
368    }
369
370    fn into_inner(
371        self,
372    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
373    {
374        (self.inner, self.is_terminated)
375    }
376
377    fn from_inner(
378        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
379        is_terminated: bool,
380    ) -> Self {
381        Self { inner, is_terminated }
382    }
383}
384
385impl futures::Stream for CalculatorRequestStream {
386    type Item = Result<CalculatorRequest, fidl::Error>;
387
388    fn poll_next(
389        mut self: std::pin::Pin<&mut Self>,
390        cx: &mut std::task::Context<'_>,
391    ) -> std::task::Poll<Option<Self::Item>> {
392        let this = &mut *self;
393        if this.inner.check_shutdown(cx) {
394            this.is_terminated = true;
395            return std::task::Poll::Ready(None);
396        }
397        if this.is_terminated {
398            panic!("polled CalculatorRequestStream after completion");
399        }
400        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
401            |bytes, handles| {
402                match this.inner.channel().read_etc(cx, bytes, handles) {
403                    std::task::Poll::Ready(Ok(())) => {}
404                    std::task::Poll::Pending => return std::task::Poll::Pending,
405                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
406                        this.is_terminated = true;
407                        return std::task::Poll::Ready(None);
408                    }
409                    std::task::Poll::Ready(Err(e)) => {
410                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
411                            e.into(),
412                        ))))
413                    }
414                }
415
416                // A message has been received from the channel
417                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
418
419                std::task::Poll::Ready(Some(match header.ordinal {
420                    0x77e89989c55e6e01 => {
421                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
422                        let mut req = fidl::new_empty!(
423                            CalculatorAddRequest,
424                            fidl::encoding::DefaultFuchsiaResourceDialect
425                        );
426                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorAddRequest>(&header, _body_bytes, handles, &mut req)?;
427                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
428                        Ok(CalculatorRequest::Add {
429                            a: req.a,
430                            b: req.b,
431
432                            responder: CalculatorAddResponder {
433                                control_handle: std::mem::ManuallyDrop::new(control_handle),
434                                tx_id: header.tx_id,
435                            },
436                        })
437                    }
438                    0x4c4ca20ded067af7 => {
439                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
440                        let mut req = fidl::new_empty!(
441                            CalculatorDivideRequest,
442                            fidl::encoding::DefaultFuchsiaResourceDialect
443                        );
444                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorDivideRequest>(&header, _body_bytes, handles, &mut req)?;
445                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
446                        Ok(CalculatorRequest::Divide {
447                            dividend: req.dividend,
448                            divisor: req.divisor,
449
450                            responder: CalculatorDivideResponder {
451                                control_handle: std::mem::ManuallyDrop::new(control_handle),
452                                tx_id: header.tx_id,
453                            },
454                        })
455                    }
456                    0x673e190d87949c89 => {
457                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
458                        let mut req = fidl::new_empty!(
459                            fidl::encoding::EmptyPayload,
460                            fidl::encoding::DefaultFuchsiaResourceDialect
461                        );
462                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
463                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
464                        Ok(CalculatorRequest::Clear { control_handle })
465                    }
466                    _ if header.tx_id == 0
467                        && header
468                            .dynamic_flags()
469                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
470                    {
471                        Ok(CalculatorRequest::_UnknownMethod {
472                            ordinal: header.ordinal,
473                            control_handle: CalculatorControlHandle { inner: this.inner.clone() },
474                            method_type: fidl::MethodType::OneWay,
475                        })
476                    }
477                    _ if header
478                        .dynamic_flags()
479                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
480                    {
481                        this.inner.send_framework_err(
482                            fidl::encoding::FrameworkErr::UnknownMethod,
483                            header.tx_id,
484                            header.ordinal,
485                            header.dynamic_flags(),
486                            (bytes, handles),
487                        )?;
488                        Ok(CalculatorRequest::_UnknownMethod {
489                            ordinal: header.ordinal,
490                            control_handle: CalculatorControlHandle { inner: this.inner.clone() },
491                            method_type: fidl::MethodType::TwoWay,
492                        })
493                    }
494                    _ => Err(fidl::Error::UnknownOrdinal {
495                        ordinal: header.ordinal,
496                        protocol_name:
497                            <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
498                    }),
499                }))
500            },
501        )
502    }
503}
504
505#[derive(Debug)]
506pub enum CalculatorRequest {
507    Add {
508        a: i32,
509        b: i32,
510        responder: CalculatorAddResponder,
511    },
512    Divide {
513        dividend: i32,
514        divisor: i32,
515        responder: CalculatorDivideResponder,
516    },
517    Clear {
518        control_handle: CalculatorControlHandle,
519    },
520    /// An interaction was received which does not match any known method.
521    #[non_exhaustive]
522    _UnknownMethod {
523        /// Ordinal of the method that was called.
524        ordinal: u64,
525        control_handle: CalculatorControlHandle,
526        method_type: fidl::MethodType,
527    },
528}
529
530impl CalculatorRequest {
531    #[allow(irrefutable_let_patterns)]
532    pub fn into_add(self) -> Option<(i32, i32, CalculatorAddResponder)> {
533        if let CalculatorRequest::Add { a, b, responder } = self {
534            Some((a, b, responder))
535        } else {
536            None
537        }
538    }
539
540    #[allow(irrefutable_let_patterns)]
541    pub fn into_divide(self) -> Option<(i32, i32, CalculatorDivideResponder)> {
542        if let CalculatorRequest::Divide { dividend, divisor, responder } = self {
543            Some((dividend, divisor, responder))
544        } else {
545            None
546        }
547    }
548
549    #[allow(irrefutable_let_patterns)]
550    pub fn into_clear(self) -> Option<(CalculatorControlHandle)> {
551        if let CalculatorRequest::Clear { control_handle } = self {
552            Some((control_handle))
553        } else {
554            None
555        }
556    }
557
558    /// Name of the method defined in FIDL
559    pub fn method_name(&self) -> &'static str {
560        match *self {
561            CalculatorRequest::Add { .. } => "add",
562            CalculatorRequest::Divide { .. } => "divide",
563            CalculatorRequest::Clear { .. } => "clear",
564            CalculatorRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
565                "unknown one-way method"
566            }
567            CalculatorRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
568                "unknown two-way method"
569            }
570        }
571    }
572}
573
574#[derive(Debug, Clone)]
575pub struct CalculatorControlHandle {
576    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
577}
578
579impl fidl::endpoints::ControlHandle for CalculatorControlHandle {
580    fn shutdown(&self) {
581        self.inner.shutdown()
582    }
583    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
584        self.inner.shutdown_with_epitaph(status)
585    }
586
587    fn is_closed(&self) -> bool {
588        self.inner.channel().is_closed()
589    }
590    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
591        self.inner.channel().on_closed()
592    }
593
594    #[cfg(target_os = "fuchsia")]
595    fn signal_peer(
596        &self,
597        clear_mask: zx::Signals,
598        set_mask: zx::Signals,
599    ) -> Result<(), zx_status::Status> {
600        use fidl::Peered;
601        self.inner.channel().signal_peer(clear_mask, set_mask)
602    }
603}
604
605impl CalculatorControlHandle {
606    pub fn send_on_error(&self, mut status_code: u32) -> Result<(), fidl::Error> {
607        self.inner.send::<CalculatorOnErrorRequest>(
608            (status_code,),
609            0,
610            0x7c1350cc0144d3fc,
611            fidl::encoding::DynamicFlags::FLEXIBLE,
612        )
613    }
614}
615
616#[must_use = "FIDL methods require a response to be sent"]
617#[derive(Debug)]
618pub struct CalculatorAddResponder {
619    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
620    tx_id: u32,
621}
622
623/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
624/// if the responder is dropped without sending a response, so that the client
625/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
626impl std::ops::Drop for CalculatorAddResponder {
627    fn drop(&mut self) {
628        self.control_handle.shutdown();
629        // Safety: drops once, never accessed again
630        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
631    }
632}
633
634impl fidl::endpoints::Responder for CalculatorAddResponder {
635    type ControlHandle = CalculatorControlHandle;
636
637    fn control_handle(&self) -> &CalculatorControlHandle {
638        &self.control_handle
639    }
640
641    fn drop_without_shutdown(mut self) {
642        // Safety: drops once, never accessed again due to mem::forget
643        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
644        // Prevent Drop from running (which would shut down the channel)
645        std::mem::forget(self);
646    }
647}
648
649impl CalculatorAddResponder {
650    /// Sends a response to the FIDL transaction.
651    ///
652    /// Sets the channel to shutdown if an error occurs.
653    pub fn send(self, mut sum: i32) -> Result<(), fidl::Error> {
654        let _result = self.send_raw(sum);
655        if _result.is_err() {
656            self.control_handle.shutdown();
657        }
658        self.drop_without_shutdown();
659        _result
660    }
661
662    /// Similar to "send" but does not shutdown the channel if an error occurs.
663    pub fn send_no_shutdown_on_err(self, mut sum: i32) -> Result<(), fidl::Error> {
664        let _result = self.send_raw(sum);
665        self.drop_without_shutdown();
666        _result
667    }
668
669    fn send_raw(&self, mut sum: i32) -> Result<(), fidl::Error> {
670        self.control_handle.inner.send::<fidl::encoding::FlexibleType<CalculatorAddResponse>>(
671            fidl::encoding::Flexible::new((sum,)),
672            self.tx_id,
673            0x77e89989c55e6e01,
674            fidl::encoding::DynamicFlags::FLEXIBLE,
675        )
676    }
677}
678
679#[must_use = "FIDL methods require a response to be sent"]
680#[derive(Debug)]
681pub struct CalculatorDivideResponder {
682    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
683    tx_id: u32,
684}
685
686/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
687/// if the responder is dropped without sending a response, so that the client
688/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
689impl std::ops::Drop for CalculatorDivideResponder {
690    fn drop(&mut self) {
691        self.control_handle.shutdown();
692        // Safety: drops once, never accessed again
693        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
694    }
695}
696
697impl fidl::endpoints::Responder for CalculatorDivideResponder {
698    type ControlHandle = CalculatorControlHandle;
699
700    fn control_handle(&self) -> &CalculatorControlHandle {
701        &self.control_handle
702    }
703
704    fn drop_without_shutdown(mut self) {
705        // Safety: drops once, never accessed again due to mem::forget
706        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
707        // Prevent Drop from running (which would shut down the channel)
708        std::mem::forget(self);
709    }
710}
711
712impl CalculatorDivideResponder {
713    /// Sends a response to the FIDL transaction.
714    ///
715    /// Sets the channel to shutdown if an error occurs.
716    pub fn send(self, mut result: Result<(i32, i32), DivisionError>) -> Result<(), fidl::Error> {
717        let _result = self.send_raw(result);
718        if _result.is_err() {
719            self.control_handle.shutdown();
720        }
721        self.drop_without_shutdown();
722        _result
723    }
724
725    /// Similar to "send" but does not shutdown the channel if an error occurs.
726    pub fn send_no_shutdown_on_err(
727        self,
728        mut result: Result<(i32, i32), DivisionError>,
729    ) -> Result<(), fidl::Error> {
730        let _result = self.send_raw(result);
731        self.drop_without_shutdown();
732        _result
733    }
734
735    fn send_raw(&self, mut result: Result<(i32, i32), DivisionError>) -> Result<(), fidl::Error> {
736        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
737            CalculatorDivideResponse,
738            DivisionError,
739        >>(
740            fidl::encoding::FlexibleResult::new(result),
741            self.tx_id,
742            0x4c4ca20ded067af7,
743            fidl::encoding::DynamicFlags::FLEXIBLE,
744        )
745    }
746}
747
748mod internal {
749    use super::*;
750}