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 { Some((status_code)) } else { None }
311    }
312
313    /// Decodes a message buffer as a [`CalculatorEvent`].
314    fn decode(
315        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
316    ) -> Result<CalculatorEvent, fidl::Error> {
317        let (bytes, _handles) = buf.split_mut();
318        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
319        debug_assert_eq!(tx_header.tx_id, 0);
320        match tx_header.ordinal {
321            0x7c1350cc0144d3fc => {
322                let mut out = fidl::new_empty!(
323                    CalculatorOnErrorRequest,
324                    fidl::encoding::DefaultFuchsiaResourceDialect
325                );
326                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorOnErrorRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
327                Ok((CalculatorEvent::OnError { status_code: out.status_code }))
328            }
329            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
330                Ok(CalculatorEvent::_UnknownEvent { ordinal: tx_header.ordinal })
331            }
332            _ => Err(fidl::Error::UnknownOrdinal {
333                ordinal: tx_header.ordinal,
334                protocol_name: <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
335            }),
336        }
337    }
338}
339
340/// A Stream of incoming requests for examples.calculator/Calculator.
341pub struct CalculatorRequestStream {
342    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
343    is_terminated: bool,
344}
345
346impl std::marker::Unpin for CalculatorRequestStream {}
347
348impl futures::stream::FusedStream for CalculatorRequestStream {
349    fn is_terminated(&self) -> bool {
350        self.is_terminated
351    }
352}
353
354impl fidl::endpoints::RequestStream for CalculatorRequestStream {
355    type Protocol = CalculatorMarker;
356    type ControlHandle = CalculatorControlHandle;
357
358    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
359        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
360    }
361
362    fn control_handle(&self) -> Self::ControlHandle {
363        CalculatorControlHandle { inner: self.inner.clone() }
364    }
365
366    fn into_inner(
367        self,
368    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
369    {
370        (self.inner, self.is_terminated)
371    }
372
373    fn from_inner(
374        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
375        is_terminated: bool,
376    ) -> Self {
377        Self { inner, is_terminated }
378    }
379}
380
381impl futures::Stream for CalculatorRequestStream {
382    type Item = Result<CalculatorRequest, fidl::Error>;
383
384    fn poll_next(
385        mut self: std::pin::Pin<&mut Self>,
386        cx: &mut std::task::Context<'_>,
387    ) -> std::task::Poll<Option<Self::Item>> {
388        let this = &mut *self;
389        if this.inner.check_shutdown(cx) {
390            this.is_terminated = true;
391            return std::task::Poll::Ready(None);
392        }
393        if this.is_terminated {
394            panic!("polled CalculatorRequestStream after completion");
395        }
396        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
397            |bytes, handles| {
398                match this.inner.channel().read_etc(cx, bytes, handles) {
399                    std::task::Poll::Ready(Ok(())) => {}
400                    std::task::Poll::Pending => return std::task::Poll::Pending,
401                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
402                        this.is_terminated = true;
403                        return std::task::Poll::Ready(None);
404                    }
405                    std::task::Poll::Ready(Err(e)) => {
406                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
407                            e.into(),
408                        ))));
409                    }
410                }
411
412                // A message has been received from the channel
413                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
414
415                std::task::Poll::Ready(Some(match header.ordinal {
416                    0x77e89989c55e6e01 => {
417                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
418                        let mut req = fidl::new_empty!(
419                            CalculatorAddRequest,
420                            fidl::encoding::DefaultFuchsiaResourceDialect
421                        );
422                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorAddRequest>(&header, _body_bytes, handles, &mut req)?;
423                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
424                        Ok(CalculatorRequest::Add {
425                            a: req.a,
426                            b: req.b,
427
428                            responder: CalculatorAddResponder {
429                                control_handle: std::mem::ManuallyDrop::new(control_handle),
430                                tx_id: header.tx_id,
431                            },
432                        })
433                    }
434                    0x4c4ca20ded067af7 => {
435                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
436                        let mut req = fidl::new_empty!(
437                            CalculatorDivideRequest,
438                            fidl::encoding::DefaultFuchsiaResourceDialect
439                        );
440                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalculatorDivideRequest>(&header, _body_bytes, handles, &mut req)?;
441                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
442                        Ok(CalculatorRequest::Divide {
443                            dividend: req.dividend,
444                            divisor: req.divisor,
445
446                            responder: CalculatorDivideResponder {
447                                control_handle: std::mem::ManuallyDrop::new(control_handle),
448                                tx_id: header.tx_id,
449                            },
450                        })
451                    }
452                    0x673e190d87949c89 => {
453                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
454                        let mut req = fidl::new_empty!(
455                            fidl::encoding::EmptyPayload,
456                            fidl::encoding::DefaultFuchsiaResourceDialect
457                        );
458                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
459                        let control_handle = CalculatorControlHandle { inner: this.inner.clone() };
460                        Ok(CalculatorRequest::Clear { control_handle })
461                    }
462                    _ if header.tx_id == 0
463                        && header
464                            .dynamic_flags()
465                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
466                    {
467                        Ok(CalculatorRequest::_UnknownMethod {
468                            ordinal: header.ordinal,
469                            control_handle: CalculatorControlHandle { inner: this.inner.clone() },
470                            method_type: fidl::MethodType::OneWay,
471                        })
472                    }
473                    _ if header
474                        .dynamic_flags()
475                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
476                    {
477                        this.inner.send_framework_err(
478                            fidl::encoding::FrameworkErr::UnknownMethod,
479                            header.tx_id,
480                            header.ordinal,
481                            header.dynamic_flags(),
482                            (bytes, handles),
483                        )?;
484                        Ok(CalculatorRequest::_UnknownMethod {
485                            ordinal: header.ordinal,
486                            control_handle: CalculatorControlHandle { inner: this.inner.clone() },
487                            method_type: fidl::MethodType::TwoWay,
488                        })
489                    }
490                    _ => Err(fidl::Error::UnknownOrdinal {
491                        ordinal: header.ordinal,
492                        protocol_name:
493                            <CalculatorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
494                    }),
495                }))
496            },
497        )
498    }
499}
500
501#[derive(Debug)]
502pub enum CalculatorRequest {
503    Add {
504        a: i32,
505        b: i32,
506        responder: CalculatorAddResponder,
507    },
508    Divide {
509        dividend: i32,
510        divisor: i32,
511        responder: CalculatorDivideResponder,
512    },
513    Clear {
514        control_handle: CalculatorControlHandle,
515    },
516    /// An interaction was received which does not match any known method.
517    #[non_exhaustive]
518    _UnknownMethod {
519        /// Ordinal of the method that was called.
520        ordinal: u64,
521        control_handle: CalculatorControlHandle,
522        method_type: fidl::MethodType,
523    },
524}
525
526impl CalculatorRequest {
527    #[allow(irrefutable_let_patterns)]
528    pub fn into_add(self) -> Option<(i32, i32, CalculatorAddResponder)> {
529        if let CalculatorRequest::Add { a, b, responder } = self {
530            Some((a, b, responder))
531        } else {
532            None
533        }
534    }
535
536    #[allow(irrefutable_let_patterns)]
537    pub fn into_divide(self) -> Option<(i32, i32, CalculatorDivideResponder)> {
538        if let CalculatorRequest::Divide { dividend, divisor, responder } = self {
539            Some((dividend, divisor, responder))
540        } else {
541            None
542        }
543    }
544
545    #[allow(irrefutable_let_patterns)]
546    pub fn into_clear(self) -> Option<(CalculatorControlHandle)> {
547        if let CalculatorRequest::Clear { control_handle } = self {
548            Some((control_handle))
549        } else {
550            None
551        }
552    }
553
554    /// Name of the method defined in FIDL
555    pub fn method_name(&self) -> &'static str {
556        match *self {
557            CalculatorRequest::Add { .. } => "add",
558            CalculatorRequest::Divide { .. } => "divide",
559            CalculatorRequest::Clear { .. } => "clear",
560            CalculatorRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
561                "unknown one-way method"
562            }
563            CalculatorRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
564                "unknown two-way method"
565            }
566        }
567    }
568}
569
570#[derive(Debug, Clone)]
571pub struct CalculatorControlHandle {
572    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
573}
574
575impl fidl::endpoints::ControlHandle for CalculatorControlHandle {
576    fn shutdown(&self) {
577        self.inner.shutdown()
578    }
579    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
580        self.inner.shutdown_with_epitaph(status)
581    }
582
583    fn is_closed(&self) -> bool {
584        self.inner.channel().is_closed()
585    }
586    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
587        self.inner.channel().on_closed()
588    }
589
590    #[cfg(target_os = "fuchsia")]
591    fn signal_peer(
592        &self,
593        clear_mask: zx::Signals,
594        set_mask: zx::Signals,
595    ) -> Result<(), zx_status::Status> {
596        use fidl::Peered;
597        self.inner.channel().signal_peer(clear_mask, set_mask)
598    }
599}
600
601impl CalculatorControlHandle {
602    pub fn send_on_error(&self, mut status_code: u32) -> Result<(), fidl::Error> {
603        self.inner.send::<CalculatorOnErrorRequest>(
604            (status_code,),
605            0,
606            0x7c1350cc0144d3fc,
607            fidl::encoding::DynamicFlags::FLEXIBLE,
608        )
609    }
610}
611
612#[must_use = "FIDL methods require a response to be sent"]
613#[derive(Debug)]
614pub struct CalculatorAddResponder {
615    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
616    tx_id: u32,
617}
618
619/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
620/// if the responder is dropped without sending a response, so that the client
621/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
622impl std::ops::Drop for CalculatorAddResponder {
623    fn drop(&mut self) {
624        self.control_handle.shutdown();
625        // Safety: drops once, never accessed again
626        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
627    }
628}
629
630impl fidl::endpoints::Responder for CalculatorAddResponder {
631    type ControlHandle = CalculatorControlHandle;
632
633    fn control_handle(&self) -> &CalculatorControlHandle {
634        &self.control_handle
635    }
636
637    fn drop_without_shutdown(mut self) {
638        // Safety: drops once, never accessed again due to mem::forget
639        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
640        // Prevent Drop from running (which would shut down the channel)
641        std::mem::forget(self);
642    }
643}
644
645impl CalculatorAddResponder {
646    /// Sends a response to the FIDL transaction.
647    ///
648    /// Sets the channel to shutdown if an error occurs.
649    pub fn send(self, mut sum: i32) -> Result<(), fidl::Error> {
650        let _result = self.send_raw(sum);
651        if _result.is_err() {
652            self.control_handle.shutdown();
653        }
654        self.drop_without_shutdown();
655        _result
656    }
657
658    /// Similar to "send" but does not shutdown the channel if an error occurs.
659    pub fn send_no_shutdown_on_err(self, mut sum: i32) -> Result<(), fidl::Error> {
660        let _result = self.send_raw(sum);
661        self.drop_without_shutdown();
662        _result
663    }
664
665    fn send_raw(&self, mut sum: i32) -> Result<(), fidl::Error> {
666        self.control_handle.inner.send::<fidl::encoding::FlexibleType<CalculatorAddResponse>>(
667            fidl::encoding::Flexible::new((sum,)),
668            self.tx_id,
669            0x77e89989c55e6e01,
670            fidl::encoding::DynamicFlags::FLEXIBLE,
671        )
672    }
673}
674
675#[must_use = "FIDL methods require a response to be sent"]
676#[derive(Debug)]
677pub struct CalculatorDivideResponder {
678    control_handle: std::mem::ManuallyDrop<CalculatorControlHandle>,
679    tx_id: u32,
680}
681
682/// Set the the channel to be shutdown (see [`CalculatorControlHandle::shutdown`])
683/// if the responder is dropped without sending a response, so that the client
684/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
685impl std::ops::Drop for CalculatorDivideResponder {
686    fn drop(&mut self) {
687        self.control_handle.shutdown();
688        // Safety: drops once, never accessed again
689        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
690    }
691}
692
693impl fidl::endpoints::Responder for CalculatorDivideResponder {
694    type ControlHandle = CalculatorControlHandle;
695
696    fn control_handle(&self) -> &CalculatorControlHandle {
697        &self.control_handle
698    }
699
700    fn drop_without_shutdown(mut self) {
701        // Safety: drops once, never accessed again due to mem::forget
702        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
703        // Prevent Drop from running (which would shut down the channel)
704        std::mem::forget(self);
705    }
706}
707
708impl CalculatorDivideResponder {
709    /// Sends a response to the FIDL transaction.
710    ///
711    /// Sets the channel to shutdown if an error occurs.
712    pub fn send(self, mut result: Result<(i32, i32), DivisionError>) -> Result<(), fidl::Error> {
713        let _result = self.send_raw(result);
714        if _result.is_err() {
715            self.control_handle.shutdown();
716        }
717        self.drop_without_shutdown();
718        _result
719    }
720
721    /// Similar to "send" but does not shutdown the channel if an error occurs.
722    pub fn send_no_shutdown_on_err(
723        self,
724        mut result: Result<(i32, i32), DivisionError>,
725    ) -> Result<(), fidl::Error> {
726        let _result = self.send_raw(result);
727        self.drop_without_shutdown();
728        _result
729    }
730
731    fn send_raw(&self, mut result: Result<(i32, i32), DivisionError>) -> Result<(), fidl::Error> {
732        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
733            CalculatorDivideResponse,
734            DivisionError,
735        >>(
736            fidl::encoding::FlexibleResult::new(result),
737            self.tx_id,
738            0x4c4ca20ded067af7,
739            fidl::encoding::DynamicFlags::FLEXIBLE,
740        )
741    }
742}
743
744mod internal {
745    use super::*;
746}