fidl_test_componentmanager_stresstests/
fidl_test_componentmanager_stresstests.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_test_componentmanager_stresstests__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ChildRealmMarker;
16
17impl fidl::endpoints::ProtocolMarker for ChildRealmMarker {
18    type Proxy = ChildRealmProxy;
19    type RequestStream = ChildRealmRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = ChildRealmSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "test.componentmanager.stresstests.ChildRealm";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ChildRealmMarker {}
26
27pub trait ChildRealmProxyInterface: Send + Sync {
28    fn r#stop(&self) -> Result<(), fidl::Error>;
29    type StopChildrenResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
30    fn r#stop_children(&self) -> Self::StopChildrenResponseFut;
31    type CreateChildrenResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
32    fn r#create_children(
33        &self,
34        direct_children: u16,
35        tree_height: u16,
36    ) -> Self::CreateChildrenResponseFut;
37}
38#[derive(Debug)]
39#[cfg(target_os = "fuchsia")]
40pub struct ChildRealmSynchronousProxy {
41    client: fidl::client::sync::Client,
42}
43
44#[cfg(target_os = "fuchsia")]
45impl fidl::endpoints::SynchronousProxy for ChildRealmSynchronousProxy {
46    type Proxy = ChildRealmProxy;
47    type Protocol = ChildRealmMarker;
48
49    fn from_channel(inner: fidl::Channel) -> Self {
50        Self::new(inner)
51    }
52
53    fn into_channel(self) -> fidl::Channel {
54        self.client.into_channel()
55    }
56
57    fn as_channel(&self) -> &fidl::Channel {
58        self.client.as_channel()
59    }
60}
61
62#[cfg(target_os = "fuchsia")]
63impl ChildRealmSynchronousProxy {
64    pub fn new(channel: fidl::Channel) -> Self {
65        let protocol_name = <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
66        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
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<ChildRealmEvent, fidl::Error> {
79        ChildRealmEvent::decode(self.client.wait_for_event(deadline)?)
80    }
81
82    /// Component will gracefully exit.
83    pub fn r#stop(&self) -> Result<(), fidl::Error> {
84        self.client.send::<fidl::encoding::EmptyPayload>(
85            (),
86            0x36c34aa66f2a56ab,
87            fidl::encoding::DynamicFlags::empty(),
88        )
89    }
90
91    pub fn r#stop_children(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
92        let _response =
93            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
94                (),
95                0x61c8762c3aa05df7,
96                fidl::encoding::DynamicFlags::empty(),
97                ___deadline,
98            )?;
99        Ok(_response)
100    }
101
102    /// Create nested children in this realm.
103    /// `direct_children` - Num of direct children of this realm.
104    /// `tree_height` - Height of the realm tree to create.
105    /// Returns once all children are running.
106    pub fn r#create_children(
107        &self,
108        mut direct_children: u16,
109        mut tree_height: u16,
110        ___deadline: zx::MonotonicInstant,
111    ) -> Result<(), fidl::Error> {
112        let _response = self
113            .client
114            .send_query::<ChildRealmCreateChildrenRequest, fidl::encoding::EmptyPayload>(
115                (direct_children, tree_height),
116                0x37a93e012377095c,
117                fidl::encoding::DynamicFlags::empty(),
118                ___deadline,
119            )?;
120        Ok(_response)
121    }
122}
123
124#[cfg(target_os = "fuchsia")]
125impl From<ChildRealmSynchronousProxy> for zx::Handle {
126    fn from(value: ChildRealmSynchronousProxy) -> Self {
127        value.into_channel().into()
128    }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl From<fidl::Channel> for ChildRealmSynchronousProxy {
133    fn from(value: fidl::Channel) -> Self {
134        Self::new(value)
135    }
136}
137
138#[cfg(target_os = "fuchsia")]
139impl fidl::endpoints::FromClient for ChildRealmSynchronousProxy {
140    type Protocol = ChildRealmMarker;
141
142    fn from_client(value: fidl::endpoints::ClientEnd<ChildRealmMarker>) -> Self {
143        Self::new(value.into_channel())
144    }
145}
146
147#[derive(Debug, Clone)]
148pub struct ChildRealmProxy {
149    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
150}
151
152impl fidl::endpoints::Proxy for ChildRealmProxy {
153    type Protocol = ChildRealmMarker;
154
155    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
156        Self::new(inner)
157    }
158
159    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
160        self.client.into_channel().map_err(|client| Self { client })
161    }
162
163    fn as_channel(&self) -> &::fidl::AsyncChannel {
164        self.client.as_channel()
165    }
166}
167
168impl ChildRealmProxy {
169    /// Create a new Proxy for test.componentmanager.stresstests/ChildRealm.
170    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
171        let protocol_name = <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
172        Self { client: fidl::client::Client::new(channel, protocol_name) }
173    }
174
175    /// Get a Stream of events from the remote end of the protocol.
176    ///
177    /// # Panics
178    ///
179    /// Panics if the event stream was already taken.
180    pub fn take_event_stream(&self) -> ChildRealmEventStream {
181        ChildRealmEventStream { event_receiver: self.client.take_event_receiver() }
182    }
183
184    /// Component will gracefully exit.
185    pub fn r#stop(&self) -> Result<(), fidl::Error> {
186        ChildRealmProxyInterface::r#stop(self)
187    }
188
189    pub fn r#stop_children(
190        &self,
191    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
192        ChildRealmProxyInterface::r#stop_children(self)
193    }
194
195    /// Create nested children in this realm.
196    /// `direct_children` - Num of direct children of this realm.
197    /// `tree_height` - Height of the realm tree to create.
198    /// Returns once all children are running.
199    pub fn r#create_children(
200        &self,
201        mut direct_children: u16,
202        mut tree_height: u16,
203    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
204        ChildRealmProxyInterface::r#create_children(self, direct_children, tree_height)
205    }
206}
207
208impl ChildRealmProxyInterface for ChildRealmProxy {
209    fn r#stop(&self) -> Result<(), fidl::Error> {
210        self.client.send::<fidl::encoding::EmptyPayload>(
211            (),
212            0x36c34aa66f2a56ab,
213            fidl::encoding::DynamicFlags::empty(),
214        )
215    }
216
217    type StopChildrenResponseFut =
218        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
219    fn r#stop_children(&self) -> Self::StopChildrenResponseFut {
220        fn _decode(
221            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
222        ) -> Result<(), fidl::Error> {
223            let _response = fidl::client::decode_transaction_body::<
224                fidl::encoding::EmptyPayload,
225                fidl::encoding::DefaultFuchsiaResourceDialect,
226                0x61c8762c3aa05df7,
227            >(_buf?)?;
228            Ok(_response)
229        }
230        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
231            (),
232            0x61c8762c3aa05df7,
233            fidl::encoding::DynamicFlags::empty(),
234            _decode,
235        )
236    }
237
238    type CreateChildrenResponseFut =
239        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
240    fn r#create_children(
241        &self,
242        mut direct_children: u16,
243        mut tree_height: u16,
244    ) -> Self::CreateChildrenResponseFut {
245        fn _decode(
246            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
247        ) -> Result<(), fidl::Error> {
248            let _response = fidl::client::decode_transaction_body::<
249                fidl::encoding::EmptyPayload,
250                fidl::encoding::DefaultFuchsiaResourceDialect,
251                0x37a93e012377095c,
252            >(_buf?)?;
253            Ok(_response)
254        }
255        self.client.send_query_and_decode::<ChildRealmCreateChildrenRequest, ()>(
256            (direct_children, tree_height),
257            0x37a93e012377095c,
258            fidl::encoding::DynamicFlags::empty(),
259            _decode,
260        )
261    }
262}
263
264pub struct ChildRealmEventStream {
265    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
266}
267
268impl std::marker::Unpin for ChildRealmEventStream {}
269
270impl futures::stream::FusedStream for ChildRealmEventStream {
271    fn is_terminated(&self) -> bool {
272        self.event_receiver.is_terminated()
273    }
274}
275
276impl futures::Stream for ChildRealmEventStream {
277    type Item = Result<ChildRealmEvent, fidl::Error>;
278
279    fn poll_next(
280        mut self: std::pin::Pin<&mut Self>,
281        cx: &mut std::task::Context<'_>,
282    ) -> std::task::Poll<Option<Self::Item>> {
283        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
284            &mut self.event_receiver,
285            cx
286        )?) {
287            Some(buf) => std::task::Poll::Ready(Some(ChildRealmEvent::decode(buf))),
288            None => std::task::Poll::Ready(None),
289        }
290    }
291}
292
293#[derive(Debug)]
294pub enum ChildRealmEvent {
295    OnConnected {},
296}
297
298impl ChildRealmEvent {
299    #[allow(irrefutable_let_patterns)]
300    pub fn into_on_connected(self) -> Option<()> {
301        if let ChildRealmEvent::OnConnected {} = self {
302            Some(())
303        } else {
304            None
305        }
306    }
307
308    /// Decodes a message buffer as a [`ChildRealmEvent`].
309    fn decode(
310        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
311    ) -> Result<ChildRealmEvent, fidl::Error> {
312        let (bytes, _handles) = buf.split_mut();
313        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
314        debug_assert_eq!(tx_header.tx_id, 0);
315        match tx_header.ordinal {
316            0x68a2f3384c114a61 => {
317                let mut out = fidl::new_empty!(
318                    fidl::encoding::EmptyPayload,
319                    fidl::encoding::DefaultFuchsiaResourceDialect
320                );
321                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&tx_header, _body_bytes, _handles, &mut out)?;
322                Ok((ChildRealmEvent::OnConnected {}))
323            }
324            _ => Err(fidl::Error::UnknownOrdinal {
325                ordinal: tx_header.ordinal,
326                protocol_name: <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
327            }),
328        }
329    }
330}
331
332/// A Stream of incoming requests for test.componentmanager.stresstests/ChildRealm.
333pub struct ChildRealmRequestStream {
334    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
335    is_terminated: bool,
336}
337
338impl std::marker::Unpin for ChildRealmRequestStream {}
339
340impl futures::stream::FusedStream for ChildRealmRequestStream {
341    fn is_terminated(&self) -> bool {
342        self.is_terminated
343    }
344}
345
346impl fidl::endpoints::RequestStream for ChildRealmRequestStream {
347    type Protocol = ChildRealmMarker;
348    type ControlHandle = ChildRealmControlHandle;
349
350    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
351        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
352    }
353
354    fn control_handle(&self) -> Self::ControlHandle {
355        ChildRealmControlHandle { inner: self.inner.clone() }
356    }
357
358    fn into_inner(
359        self,
360    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
361    {
362        (self.inner, self.is_terminated)
363    }
364
365    fn from_inner(
366        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
367        is_terminated: bool,
368    ) -> Self {
369        Self { inner, is_terminated }
370    }
371}
372
373impl futures::Stream for ChildRealmRequestStream {
374    type Item = Result<ChildRealmRequest, fidl::Error>;
375
376    fn poll_next(
377        mut self: std::pin::Pin<&mut Self>,
378        cx: &mut std::task::Context<'_>,
379    ) -> std::task::Poll<Option<Self::Item>> {
380        let this = &mut *self;
381        if this.inner.check_shutdown(cx) {
382            this.is_terminated = true;
383            return std::task::Poll::Ready(None);
384        }
385        if this.is_terminated {
386            panic!("polled ChildRealmRequestStream after completion");
387        }
388        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
389            |bytes, handles| {
390                match this.inner.channel().read_etc(cx, bytes, handles) {
391                    std::task::Poll::Ready(Ok(())) => {}
392                    std::task::Poll::Pending => return std::task::Poll::Pending,
393                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
394                        this.is_terminated = true;
395                        return std::task::Poll::Ready(None);
396                    }
397                    std::task::Poll::Ready(Err(e)) => {
398                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
399                            e.into(),
400                        ))))
401                    }
402                }
403
404                // A message has been received from the channel
405                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
406
407                std::task::Poll::Ready(Some(match header.ordinal {
408                    0x36c34aa66f2a56ab => {
409                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
410                        let mut req = fidl::new_empty!(
411                            fidl::encoding::EmptyPayload,
412                            fidl::encoding::DefaultFuchsiaResourceDialect
413                        );
414                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
415                        let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
416                        Ok(ChildRealmRequest::Stop { control_handle })
417                    }
418                    0x61c8762c3aa05df7 => {
419                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
420                        let mut req = fidl::new_empty!(
421                            fidl::encoding::EmptyPayload,
422                            fidl::encoding::DefaultFuchsiaResourceDialect
423                        );
424                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
425                        let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
426                        Ok(ChildRealmRequest::StopChildren {
427                            responder: ChildRealmStopChildrenResponder {
428                                control_handle: std::mem::ManuallyDrop::new(control_handle),
429                                tx_id: header.tx_id,
430                            },
431                        })
432                    }
433                    0x37a93e012377095c => {
434                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
435                        let mut req = fidl::new_empty!(
436                            ChildRealmCreateChildrenRequest,
437                            fidl::encoding::DefaultFuchsiaResourceDialect
438                        );
439                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChildRealmCreateChildrenRequest>(&header, _body_bytes, handles, &mut req)?;
440                        let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
441                        Ok(ChildRealmRequest::CreateChildren {
442                            direct_children: req.direct_children,
443                            tree_height: req.tree_height,
444
445                            responder: ChildRealmCreateChildrenResponder {
446                                control_handle: std::mem::ManuallyDrop::new(control_handle),
447                                tx_id: header.tx_id,
448                            },
449                        })
450                    }
451                    _ => Err(fidl::Error::UnknownOrdinal {
452                        ordinal: header.ordinal,
453                        protocol_name:
454                            <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
455                    }),
456                }))
457            },
458        )
459    }
460}
461
462/// The way for parent to conrtol lifecycle of its child in a stress test.
463#[derive(Debug)]
464pub enum ChildRealmRequest {
465    /// Component will gracefully exit.
466    Stop {
467        control_handle: ChildRealmControlHandle,
468    },
469    StopChildren {
470        responder: ChildRealmStopChildrenResponder,
471    },
472    /// Create nested children in this realm.
473    /// `direct_children` - Num of direct children of this realm.
474    /// `tree_height` - Height of the realm tree to create.
475    /// Returns once all children are running.
476    CreateChildren {
477        direct_children: u16,
478        tree_height: u16,
479        responder: ChildRealmCreateChildrenResponder,
480    },
481}
482
483impl ChildRealmRequest {
484    #[allow(irrefutable_let_patterns)]
485    pub fn into_stop(self) -> Option<(ChildRealmControlHandle)> {
486        if let ChildRealmRequest::Stop { control_handle } = self {
487            Some((control_handle))
488        } else {
489            None
490        }
491    }
492
493    #[allow(irrefutable_let_patterns)]
494    pub fn into_stop_children(self) -> Option<(ChildRealmStopChildrenResponder)> {
495        if let ChildRealmRequest::StopChildren { responder } = self {
496            Some((responder))
497        } else {
498            None
499        }
500    }
501
502    #[allow(irrefutable_let_patterns)]
503    pub fn into_create_children(self) -> Option<(u16, u16, ChildRealmCreateChildrenResponder)> {
504        if let ChildRealmRequest::CreateChildren { direct_children, tree_height, responder } = self
505        {
506            Some((direct_children, tree_height, responder))
507        } else {
508            None
509        }
510    }
511
512    /// Name of the method defined in FIDL
513    pub fn method_name(&self) -> &'static str {
514        match *self {
515            ChildRealmRequest::Stop { .. } => "stop",
516            ChildRealmRequest::StopChildren { .. } => "stop_children",
517            ChildRealmRequest::CreateChildren { .. } => "create_children",
518        }
519    }
520}
521
522#[derive(Debug, Clone)]
523pub struct ChildRealmControlHandle {
524    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
525}
526
527impl fidl::endpoints::ControlHandle for ChildRealmControlHandle {
528    fn shutdown(&self) {
529        self.inner.shutdown()
530    }
531    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
532        self.inner.shutdown_with_epitaph(status)
533    }
534
535    fn is_closed(&self) -> bool {
536        self.inner.channel().is_closed()
537    }
538    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
539        self.inner.channel().on_closed()
540    }
541
542    #[cfg(target_os = "fuchsia")]
543    fn signal_peer(
544        &self,
545        clear_mask: zx::Signals,
546        set_mask: zx::Signals,
547    ) -> Result<(), zx_status::Status> {
548        use fidl::Peered;
549        self.inner.channel().signal_peer(clear_mask, set_mask)
550    }
551}
552
553impl ChildRealmControlHandle {
554    pub fn send_on_connected(&self) -> Result<(), fidl::Error> {
555        self.inner.send::<fidl::encoding::EmptyPayload>(
556            (),
557            0,
558            0x68a2f3384c114a61,
559            fidl::encoding::DynamicFlags::empty(),
560        )
561    }
562}
563
564#[must_use = "FIDL methods require a response to be sent"]
565#[derive(Debug)]
566pub struct ChildRealmStopChildrenResponder {
567    control_handle: std::mem::ManuallyDrop<ChildRealmControlHandle>,
568    tx_id: u32,
569}
570
571/// Set the the channel to be shutdown (see [`ChildRealmControlHandle::shutdown`])
572/// if the responder is dropped without sending a response, so that the client
573/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
574impl std::ops::Drop for ChildRealmStopChildrenResponder {
575    fn drop(&mut self) {
576        self.control_handle.shutdown();
577        // Safety: drops once, never accessed again
578        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
579    }
580}
581
582impl fidl::endpoints::Responder for ChildRealmStopChildrenResponder {
583    type ControlHandle = ChildRealmControlHandle;
584
585    fn control_handle(&self) -> &ChildRealmControlHandle {
586        &self.control_handle
587    }
588
589    fn drop_without_shutdown(mut self) {
590        // Safety: drops once, never accessed again due to mem::forget
591        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
592        // Prevent Drop from running (which would shut down the channel)
593        std::mem::forget(self);
594    }
595}
596
597impl ChildRealmStopChildrenResponder {
598    /// Sends a response to the FIDL transaction.
599    ///
600    /// Sets the channel to shutdown if an error occurs.
601    pub fn send(self) -> Result<(), fidl::Error> {
602        let _result = self.send_raw();
603        if _result.is_err() {
604            self.control_handle.shutdown();
605        }
606        self.drop_without_shutdown();
607        _result
608    }
609
610    /// Similar to "send" but does not shutdown the channel if an error occurs.
611    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
612        let _result = self.send_raw();
613        self.drop_without_shutdown();
614        _result
615    }
616
617    fn send_raw(&self) -> Result<(), fidl::Error> {
618        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
619            (),
620            self.tx_id,
621            0x61c8762c3aa05df7,
622            fidl::encoding::DynamicFlags::empty(),
623        )
624    }
625}
626
627#[must_use = "FIDL methods require a response to be sent"]
628#[derive(Debug)]
629pub struct ChildRealmCreateChildrenResponder {
630    control_handle: std::mem::ManuallyDrop<ChildRealmControlHandle>,
631    tx_id: u32,
632}
633
634/// Set the the channel to be shutdown (see [`ChildRealmControlHandle::shutdown`])
635/// if the responder is dropped without sending a response, so that the client
636/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
637impl std::ops::Drop for ChildRealmCreateChildrenResponder {
638    fn drop(&mut self) {
639        self.control_handle.shutdown();
640        // Safety: drops once, never accessed again
641        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
642    }
643}
644
645impl fidl::endpoints::Responder for ChildRealmCreateChildrenResponder {
646    type ControlHandle = ChildRealmControlHandle;
647
648    fn control_handle(&self) -> &ChildRealmControlHandle {
649        &self.control_handle
650    }
651
652    fn drop_without_shutdown(mut self) {
653        // Safety: drops once, never accessed again due to mem::forget
654        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
655        // Prevent Drop from running (which would shut down the channel)
656        std::mem::forget(self);
657    }
658}
659
660impl ChildRealmCreateChildrenResponder {
661    /// Sends a response to the FIDL transaction.
662    ///
663    /// Sets the channel to shutdown if an error occurs.
664    pub fn send(self) -> Result<(), fidl::Error> {
665        let _result = self.send_raw();
666        if _result.is_err() {
667            self.control_handle.shutdown();
668        }
669        self.drop_without_shutdown();
670        _result
671    }
672
673    /// Similar to "send" but does not shutdown the channel if an error occurs.
674    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
675        let _result = self.send_raw();
676        self.drop_without_shutdown();
677        _result
678    }
679
680    fn send_raw(&self) -> Result<(), fidl::Error> {
681        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
682            (),
683            self.tx_id,
684            0x37a93e012377095c,
685            fidl::encoding::DynamicFlags::empty(),
686        )
687    }
688}
689
690mod internal {
691    use super::*;
692}