Skip to main content

fdomain_fuchsia_net_interfaces/
fdomain_fuchsia_net_interfaces.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 fdomain_client::fidl::{ControlHandle as _, FDomainFlexibleIntoResult as _, Responder as _};
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9pub use fidl_fuchsia_net_interfaces_common::*;
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Debug, PartialEq)]
14pub struct StateGetWatcherRequest {
15    /// Options for configuring the interface state watcher.
16    pub options: WatcherOptions,
17    pub watcher: fdomain_client::fidl::ServerEnd<WatcherMarker>,
18}
19
20impl fidl::Standalone<fdomain_client::fidl::FDomainResourceDialect> for StateGetWatcherRequest {}
21
22#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
23pub struct StateMarker;
24
25impl fdomain_client::fidl::ProtocolMarker for StateMarker {
26    type Proxy = StateProxy;
27    type RequestStream = StateRequestStream;
28
29    const DEBUG_NAME: &'static str = "fuchsia.net.interfaces.State";
30}
31impl fdomain_client::fidl::DiscoverableProtocolMarker for StateMarker {}
32
33pub trait StateProxyInterface: Send + Sync {
34    fn r#get_watcher(
35        &self,
36        options: &WatcherOptions,
37        watcher: fdomain_client::fidl::ServerEnd<WatcherMarker>,
38    ) -> Result<(), fidl::Error>;
39}
40
41#[derive(Debug, Clone)]
42pub struct StateProxy {
43    client: fidl::client::Client<fdomain_client::fidl::FDomainResourceDialect>,
44}
45
46impl fdomain_client::fidl::Proxy for StateProxy {
47    type Protocol = StateMarker;
48
49    fn from_channel(inner: fdomain_client::Channel) -> Self {
50        Self::new(inner)
51    }
52
53    fn into_channel(self) -> Result<fdomain_client::Channel, Self> {
54        self.client.into_channel().map_err(|client| Self { client })
55    }
56
57    fn as_channel(&self) -> &fdomain_client::Channel {
58        self.client.as_channel()
59    }
60}
61
62impl StateProxy {
63    /// Create a new Proxy for fuchsia.net.interfaces/State.
64    pub fn new(channel: fdomain_client::Channel) -> Self {
65        let protocol_name = <StateMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME;
66        Self { client: fidl::client::Client::new(channel, protocol_name) }
67    }
68
69    /// Get a Stream of events from the remote end of the protocol.
70    ///
71    /// # Panics
72    ///
73    /// Panics if the event stream was already taken.
74    pub fn take_event_stream(&self) -> StateEventStream {
75        StateEventStream { event_receiver: self.client.take_event_receiver() }
76    }
77
78    /// Initialize a watcher for interface state.
79    ///
80    /// The server enqueues interface addition, deletion and property changes as
81    /// they occur, which can then be retrieved via the pipelined protocol.
82    ///
83    /// + request `options` specifies the behavior of the [`Watcher`].
84    /// + request `watcher` grants access to a [`Watcher`]. Closed if the queue
85    ///     cannot be allocated or if the queue is full when the server attempts
86    ///     to enqueue an event.
87    pub fn r#get_watcher(
88        &self,
89        mut options: &WatcherOptions,
90        mut watcher: fdomain_client::fidl::ServerEnd<WatcherMarker>,
91    ) -> Result<(), fidl::Error> {
92        StateProxyInterface::r#get_watcher(self, options, watcher)
93    }
94}
95
96impl StateProxyInterface for StateProxy {
97    fn r#get_watcher(
98        &self,
99        mut options: &WatcherOptions,
100        mut watcher: fdomain_client::fidl::ServerEnd<WatcherMarker>,
101    ) -> Result<(), fidl::Error> {
102        self.client.send::<StateGetWatcherRequest>(
103            (options, watcher),
104            0x4fe223c98b263ae3,
105            fidl::encoding::DynamicFlags::empty(),
106        )
107    }
108}
109
110pub struct StateEventStream {
111    event_receiver: fidl::client::EventReceiver<fdomain_client::fidl::FDomainResourceDialect>,
112}
113
114impl std::marker::Unpin for StateEventStream {}
115
116impl futures::stream::FusedStream for StateEventStream {
117    fn is_terminated(&self) -> bool {
118        self.event_receiver.is_terminated()
119    }
120}
121
122impl futures::Stream for StateEventStream {
123    type Item = Result<StateEvent, fidl::Error>;
124
125    fn poll_next(
126        mut self: std::pin::Pin<&mut Self>,
127        cx: &mut std::task::Context<'_>,
128    ) -> std::task::Poll<Option<Self::Item>> {
129        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
130            &mut self.event_receiver,
131            cx
132        )?) {
133            Some(buf) => std::task::Poll::Ready(Some(StateEvent::decode(buf))),
134            None => std::task::Poll::Ready(None),
135        }
136    }
137}
138
139#[derive(Debug)]
140pub enum StateEvent {}
141
142impl StateEvent {
143    /// Decodes a message buffer as a [`StateEvent`].
144    fn decode(
145        mut buf: <fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
146    ) -> Result<StateEvent, fidl::Error> {
147        let (bytes, _handles) = buf.split_mut();
148        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
149        debug_assert_eq!(tx_header.tx_id, 0);
150        match tx_header.ordinal {
151            _ => Err(fidl::Error::UnknownOrdinal {
152                ordinal: tx_header.ordinal,
153                protocol_name: <StateMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
154            }),
155        }
156    }
157}
158
159/// A Stream of incoming requests for fuchsia.net.interfaces/State.
160pub struct StateRequestStream {
161    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
162    is_terminated: bool,
163}
164
165impl std::marker::Unpin for StateRequestStream {}
166
167impl futures::stream::FusedStream for StateRequestStream {
168    fn is_terminated(&self) -> bool {
169        self.is_terminated
170    }
171}
172
173impl fdomain_client::fidl::RequestStream for StateRequestStream {
174    type Protocol = StateMarker;
175    type ControlHandle = StateControlHandle;
176
177    fn from_channel(channel: fdomain_client::Channel) -> Self {
178        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
179    }
180
181    fn control_handle(&self) -> Self::ControlHandle {
182        StateControlHandle { inner: self.inner.clone() }
183    }
184
185    fn into_inner(
186        self,
187    ) -> (::std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>, bool)
188    {
189        (self.inner, self.is_terminated)
190    }
191
192    fn from_inner(
193        inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
194        is_terminated: bool,
195    ) -> Self {
196        Self { inner, is_terminated }
197    }
198}
199
200impl futures::Stream for StateRequestStream {
201    type Item = Result<StateRequest, fidl::Error>;
202
203    fn poll_next(
204        mut self: std::pin::Pin<&mut Self>,
205        cx: &mut std::task::Context<'_>,
206    ) -> std::task::Poll<Option<Self::Item>> {
207        let this = &mut *self;
208        if this.inner.check_shutdown(cx) {
209            this.is_terminated = true;
210            return std::task::Poll::Ready(None);
211        }
212        if this.is_terminated {
213            panic!("polled StateRequestStream after completion");
214        }
215        fidl::encoding::with_tls_decode_buf::<_, fdomain_client::fidl::FDomainResourceDialect>(
216            |bytes, handles| {
217                match this.inner.channel().read_etc(cx, bytes, handles) {
218                    std::task::Poll::Ready(Ok(())) => {}
219                    std::task::Poll::Pending => return std::task::Poll::Pending,
220                    std::task::Poll::Ready(Err(None)) => {
221                        this.is_terminated = true;
222                        return std::task::Poll::Ready(None);
223                    }
224                    std::task::Poll::Ready(Err(Some(e))) => {
225                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
226                            e.into(),
227                        ))));
228                    }
229                }
230
231                // A message has been received from the channel
232                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
233
234                std::task::Poll::Ready(Some(match header.ordinal {
235                    0x4fe223c98b263ae3 => {
236                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
237                        let mut req = fidl::new_empty!(
238                            StateGetWatcherRequest,
239                            fdomain_client::fidl::FDomainResourceDialect
240                        );
241                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<StateGetWatcherRequest>(&header, _body_bytes, handles, &mut req)?;
242                        let control_handle = StateControlHandle { inner: this.inner.clone() };
243                        Ok(StateRequest::GetWatcher {
244                            options: req.options,
245                            watcher: req.watcher,
246
247                            control_handle,
248                        })
249                    }
250                    _ => Err(fidl::Error::UnknownOrdinal {
251                        ordinal: header.ordinal,
252                        protocol_name:
253                            <StateMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
254                    }),
255                }))
256            },
257        )
258    }
259}
260
261/// Network interface state inspection and observation.
262#[derive(Debug)]
263pub enum StateRequest {
264    /// Initialize a watcher for interface state.
265    ///
266    /// The server enqueues interface addition, deletion and property changes as
267    /// they occur, which can then be retrieved via the pipelined protocol.
268    ///
269    /// + request `options` specifies the behavior of the [`Watcher`].
270    /// + request `watcher` grants access to a [`Watcher`]. Closed if the queue
271    ///     cannot be allocated or if the queue is full when the server attempts
272    ///     to enqueue an event.
273    GetWatcher {
274        options: WatcherOptions,
275        watcher: fdomain_client::fidl::ServerEnd<WatcherMarker>,
276        control_handle: StateControlHandle,
277    },
278}
279
280impl StateRequest {
281    #[allow(irrefutable_let_patterns)]
282    pub fn into_get_watcher(
283        self,
284    ) -> Option<(WatcherOptions, fdomain_client::fidl::ServerEnd<WatcherMarker>, StateControlHandle)>
285    {
286        if let StateRequest::GetWatcher { options, watcher, control_handle } = self {
287            Some((options, watcher, control_handle))
288        } else {
289            None
290        }
291    }
292
293    /// Name of the method defined in FIDL
294    pub fn method_name(&self) -> &'static str {
295        match *self {
296            StateRequest::GetWatcher { .. } => "get_watcher",
297        }
298    }
299}
300
301#[derive(Debug, Clone)]
302pub struct StateControlHandle {
303    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
304}
305
306impl fdomain_client::fidl::ControlHandle for StateControlHandle {
307    fn shutdown(&self) {
308        self.inner.shutdown()
309    }
310
311    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
312        self.inner.shutdown_with_epitaph(status)
313    }
314
315    fn is_closed(&self) -> bool {
316        self.inner.channel().is_closed()
317    }
318    fn on_closed(&self) -> fdomain_client::OnFDomainSignals {
319        self.inner.channel().on_closed()
320    }
321}
322
323impl StateControlHandle {}
324
325#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
326pub struct WatcherMarker;
327
328impl fdomain_client::fidl::ProtocolMarker for WatcherMarker {
329    type Proxy = WatcherProxy;
330    type RequestStream = WatcherRequestStream;
331
332    const DEBUG_NAME: &'static str = "(anonymous) Watcher";
333}
334
335pub trait WatcherProxyInterface: Send + Sync {
336    type WatchResponseFut: std::future::Future<Output = Result<Event, fidl::Error>> + Send;
337    fn r#watch(&self) -> Self::WatchResponseFut;
338}
339
340#[derive(Debug, Clone)]
341pub struct WatcherProxy {
342    client: fidl::client::Client<fdomain_client::fidl::FDomainResourceDialect>,
343}
344
345impl fdomain_client::fidl::Proxy for WatcherProxy {
346    type Protocol = WatcherMarker;
347
348    fn from_channel(inner: fdomain_client::Channel) -> Self {
349        Self::new(inner)
350    }
351
352    fn into_channel(self) -> Result<fdomain_client::Channel, Self> {
353        self.client.into_channel().map_err(|client| Self { client })
354    }
355
356    fn as_channel(&self) -> &fdomain_client::Channel {
357        self.client.as_channel()
358    }
359}
360
361impl WatcherProxy {
362    /// Create a new Proxy for fuchsia.net.interfaces/Watcher.
363    pub fn new(channel: fdomain_client::Channel) -> Self {
364        let protocol_name = <WatcherMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME;
365        Self { client: fidl::client::Client::new(channel, protocol_name) }
366    }
367
368    /// Get a Stream of events from the remote end of the protocol.
369    ///
370    /// # Panics
371    ///
372    /// Panics if the event stream was already taken.
373    pub fn take_event_stream(&self) -> WatcherEventStream {
374        WatcherEventStream { event_receiver: self.client.take_event_receiver() }
375    }
376
377    /// Hanging get for an interface addition/deletion change.
378    ///
379    /// Clients should only have one call of this method at a time; a second
380    /// call to this method while a call is already pending will cause the
381    /// server end of the protocol to be closed.
382    ///
383    /// If there are N interfaces present at the time the server end of the
384    /// protocol is initialized, then the first N invocations of this method
385    /// will return [`Event.existing`] followed by a single [`Event.idle`]
386    /// indicating that all existing interfaces have been sent. Subsequent calls
387    /// will immediately return if there is a change to be reported, or block
388    /// until a change occurs.
389    ///
390    /// The server may choose to coalesce property change events, e.g. when
391    /// multiple independent property changes occur. As a result, clients cannot
392    /// assume that the order in which they observe the interface changes is the
393    /// order in which the changes occurred.
394    ///
395    /// - response `event` the interface change event.
396    pub fn r#watch(
397        &self,
398    ) -> fidl::client::QueryResponseFut<Event, fdomain_client::fidl::FDomainResourceDialect> {
399        WatcherProxyInterface::r#watch(self)
400    }
401}
402
403impl WatcherProxyInterface for WatcherProxy {
404    type WatchResponseFut =
405        fidl::client::QueryResponseFut<Event, fdomain_client::fidl::FDomainResourceDialect>;
406    fn r#watch(&self) -> Self::WatchResponseFut {
407        fn _decode(
408            mut _buf: Result<<fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
409        ) -> Result<Event, fidl::Error> {
410            let _response = fidl::client::decode_transaction_body::<
411                WatcherWatchResponse,
412                fdomain_client::fidl::FDomainResourceDialect,
413                0x550767aa9faeeef3,
414            >(_buf?)?;
415            Ok(_response.event)
416        }
417        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Event>(
418            (),
419            0x550767aa9faeeef3,
420            fidl::encoding::DynamicFlags::empty(),
421            _decode,
422        )
423    }
424}
425
426pub struct WatcherEventStream {
427    event_receiver: fidl::client::EventReceiver<fdomain_client::fidl::FDomainResourceDialect>,
428}
429
430impl std::marker::Unpin for WatcherEventStream {}
431
432impl futures::stream::FusedStream for WatcherEventStream {
433    fn is_terminated(&self) -> bool {
434        self.event_receiver.is_terminated()
435    }
436}
437
438impl futures::Stream for WatcherEventStream {
439    type Item = Result<WatcherEvent, fidl::Error>;
440
441    fn poll_next(
442        mut self: std::pin::Pin<&mut Self>,
443        cx: &mut std::task::Context<'_>,
444    ) -> std::task::Poll<Option<Self::Item>> {
445        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
446            &mut self.event_receiver,
447            cx
448        )?) {
449            Some(buf) => std::task::Poll::Ready(Some(WatcherEvent::decode(buf))),
450            None => std::task::Poll::Ready(None),
451        }
452    }
453}
454
455#[derive(Debug)]
456pub enum WatcherEvent {}
457
458impl WatcherEvent {
459    /// Decodes a message buffer as a [`WatcherEvent`].
460    fn decode(
461        mut buf: <fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
462    ) -> Result<WatcherEvent, fidl::Error> {
463        let (bytes, _handles) = buf.split_mut();
464        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
465        debug_assert_eq!(tx_header.tx_id, 0);
466        match tx_header.ordinal {
467            _ => Err(fidl::Error::UnknownOrdinal {
468                ordinal: tx_header.ordinal,
469                protocol_name: <WatcherMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
470            }),
471        }
472    }
473}
474
475/// A Stream of incoming requests for fuchsia.net.interfaces/Watcher.
476pub struct WatcherRequestStream {
477    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
478    is_terminated: bool,
479}
480
481impl std::marker::Unpin for WatcherRequestStream {}
482
483impl futures::stream::FusedStream for WatcherRequestStream {
484    fn is_terminated(&self) -> bool {
485        self.is_terminated
486    }
487}
488
489impl fdomain_client::fidl::RequestStream for WatcherRequestStream {
490    type Protocol = WatcherMarker;
491    type ControlHandle = WatcherControlHandle;
492
493    fn from_channel(channel: fdomain_client::Channel) -> Self {
494        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
495    }
496
497    fn control_handle(&self) -> Self::ControlHandle {
498        WatcherControlHandle { inner: self.inner.clone() }
499    }
500
501    fn into_inner(
502        self,
503    ) -> (::std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>, bool)
504    {
505        (self.inner, self.is_terminated)
506    }
507
508    fn from_inner(
509        inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
510        is_terminated: bool,
511    ) -> Self {
512        Self { inner, is_terminated }
513    }
514}
515
516impl futures::Stream for WatcherRequestStream {
517    type Item = Result<WatcherRequest, fidl::Error>;
518
519    fn poll_next(
520        mut self: std::pin::Pin<&mut Self>,
521        cx: &mut std::task::Context<'_>,
522    ) -> std::task::Poll<Option<Self::Item>> {
523        let this = &mut *self;
524        if this.inner.check_shutdown(cx) {
525            this.is_terminated = true;
526            return std::task::Poll::Ready(None);
527        }
528        if this.is_terminated {
529            panic!("polled WatcherRequestStream after completion");
530        }
531        fidl::encoding::with_tls_decode_buf::<_, fdomain_client::fidl::FDomainResourceDialect>(
532            |bytes, handles| {
533                match this.inner.channel().read_etc(cx, bytes, handles) {
534                    std::task::Poll::Ready(Ok(())) => {}
535                    std::task::Poll::Pending => return std::task::Poll::Pending,
536                    std::task::Poll::Ready(Err(None)) => {
537                        this.is_terminated = true;
538                        return std::task::Poll::Ready(None);
539                    }
540                    std::task::Poll::Ready(Err(Some(e))) => {
541                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
542                            e.into(),
543                        ))));
544                    }
545                }
546
547                // A message has been received from the channel
548                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
549
550                std::task::Poll::Ready(Some(match header.ordinal {
551                    0x550767aa9faeeef3 => {
552                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
553                        let mut req = fidl::new_empty!(
554                            fidl::encoding::EmptyPayload,
555                            fdomain_client::fidl::FDomainResourceDialect
556                        );
557                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
558                        let control_handle = WatcherControlHandle { inner: this.inner.clone() };
559                        Ok(WatcherRequest::Watch {
560                            responder: WatcherWatchResponder {
561                                control_handle: std::mem::ManuallyDrop::new(control_handle),
562                                tx_id: header.tx_id,
563                            },
564                        })
565                    }
566                    _ => Err(fidl::Error::UnknownOrdinal {
567                        ordinal: header.ordinal,
568                        protocol_name:
569                            <WatcherMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
570                    }),
571                }))
572            },
573        )
574    }
575}
576
577/// Observer protocol for changes to network interfaces (addition, deletion, and
578/// interface property changes).
579#[derive(Debug)]
580pub enum WatcherRequest {
581    /// Hanging get for an interface addition/deletion change.
582    ///
583    /// Clients should only have one call of this method at a time; a second
584    /// call to this method while a call is already pending will cause the
585    /// server end of the protocol to be closed.
586    ///
587    /// If there are N interfaces present at the time the server end of the
588    /// protocol is initialized, then the first N invocations of this method
589    /// will return [`Event.existing`] followed by a single [`Event.idle`]
590    /// indicating that all existing interfaces have been sent. Subsequent calls
591    /// will immediately return if there is a change to be reported, or block
592    /// until a change occurs.
593    ///
594    /// The server may choose to coalesce property change events, e.g. when
595    /// multiple independent property changes occur. As a result, clients cannot
596    /// assume that the order in which they observe the interface changes is the
597    /// order in which the changes occurred.
598    ///
599    /// - response `event` the interface change event.
600    Watch { responder: WatcherWatchResponder },
601}
602
603impl WatcherRequest {
604    #[allow(irrefutable_let_patterns)]
605    pub fn into_watch(self) -> Option<(WatcherWatchResponder)> {
606        if let WatcherRequest::Watch { responder } = self { Some((responder)) } else { None }
607    }
608
609    /// Name of the method defined in FIDL
610    pub fn method_name(&self) -> &'static str {
611        match *self {
612            WatcherRequest::Watch { .. } => "watch",
613        }
614    }
615}
616
617#[derive(Debug, Clone)]
618pub struct WatcherControlHandle {
619    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
620}
621
622impl fdomain_client::fidl::ControlHandle for WatcherControlHandle {
623    fn shutdown(&self) {
624        self.inner.shutdown()
625    }
626
627    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
628        self.inner.shutdown_with_epitaph(status)
629    }
630
631    fn is_closed(&self) -> bool {
632        self.inner.channel().is_closed()
633    }
634    fn on_closed(&self) -> fdomain_client::OnFDomainSignals {
635        self.inner.channel().on_closed()
636    }
637}
638
639impl WatcherControlHandle {}
640
641#[must_use = "FIDL methods require a response to be sent"]
642#[derive(Debug)]
643pub struct WatcherWatchResponder {
644    control_handle: std::mem::ManuallyDrop<WatcherControlHandle>,
645    tx_id: u32,
646}
647
648/// Set the the channel to be shutdown (see [`WatcherControlHandle::shutdown`])
649/// if the responder is dropped without sending a response, so that the client
650/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
651impl std::ops::Drop for WatcherWatchResponder {
652    fn drop(&mut self) {
653        self.control_handle.shutdown();
654        // Safety: drops once, never accessed again
655        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
656    }
657}
658
659impl fdomain_client::fidl::Responder for WatcherWatchResponder {
660    type ControlHandle = WatcherControlHandle;
661
662    fn control_handle(&self) -> &WatcherControlHandle {
663        &self.control_handle
664    }
665
666    fn drop_without_shutdown(mut self) {
667        // Safety: drops once, never accessed again due to mem::forget
668        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
669        // Prevent Drop from running (which would shut down the channel)
670        std::mem::forget(self);
671    }
672}
673
674impl WatcherWatchResponder {
675    /// Sends a response to the FIDL transaction.
676    ///
677    /// Sets the channel to shutdown if an error occurs.
678    pub fn send(self, mut event: &Event) -> Result<(), fidl::Error> {
679        let _result = self.send_raw(event);
680        if _result.is_err() {
681            self.control_handle.shutdown();
682        }
683        self.drop_without_shutdown();
684        _result
685    }
686
687    /// Similar to "send" but does not shutdown the channel if an error occurs.
688    pub fn send_no_shutdown_on_err(self, mut event: &Event) -> Result<(), fidl::Error> {
689        let _result = self.send_raw(event);
690        self.drop_without_shutdown();
691        _result
692    }
693
694    fn send_raw(&self, mut event: &Event) -> Result<(), fidl::Error> {
695        self.control_handle.inner.send::<WatcherWatchResponse>(
696            (event,),
697            self.tx_id,
698            0x550767aa9faeeef3,
699            fidl::encoding::DynamicFlags::empty(),
700        )
701    }
702}
703
704mod internal {
705    use super::*;
706
707    impl fidl::encoding::ResourceTypeMarker for StateGetWatcherRequest {
708        type Borrowed<'a> = &'a mut Self;
709        fn take_or_borrow<'a>(
710            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
711        ) -> Self::Borrowed<'a> {
712            value
713        }
714    }
715
716    unsafe impl fidl::encoding::TypeMarker for StateGetWatcherRequest {
717        type Owned = Self;
718
719        #[inline(always)]
720        fn inline_align(_context: fidl::encoding::Context) -> usize {
721            8
722        }
723
724        #[inline(always)]
725        fn inline_size(_context: fidl::encoding::Context) -> usize {
726            24
727        }
728    }
729
730    unsafe impl
731        fidl::encoding::Encode<StateGetWatcherRequest, fdomain_client::fidl::FDomainResourceDialect>
732        for &mut StateGetWatcherRequest
733    {
734        #[inline]
735        unsafe fn encode(
736            self,
737            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
738            offset: usize,
739            _depth: fidl::encoding::Depth,
740        ) -> fidl::Result<()> {
741            encoder.debug_check_bounds::<StateGetWatcherRequest>(offset);
742            // Delegate to tuple encoding.
743            fidl::encoding::Encode::<StateGetWatcherRequest, fdomain_client::fidl::FDomainResourceDialect>::encode(
744                (
745                    <WatcherOptions as fidl::encoding::ValueTypeMarker>::borrow(&self.options),
746                    <fidl::encoding::Endpoint<fdomain_client::fidl::ServerEnd<WatcherMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.watcher),
747                ),
748                encoder, offset, _depth
749            )
750        }
751    }
752    unsafe impl<
753        T0: fidl::encoding::Encode<WatcherOptions, fdomain_client::fidl::FDomainResourceDialect>,
754        T1: fidl::encoding::Encode<
755                fidl::encoding::Endpoint<fdomain_client::fidl::ServerEnd<WatcherMarker>>,
756                fdomain_client::fidl::FDomainResourceDialect,
757            >,
758    >
759        fidl::encoding::Encode<StateGetWatcherRequest, fdomain_client::fidl::FDomainResourceDialect>
760        for (T0, T1)
761    {
762        #[inline]
763        unsafe fn encode(
764            self,
765            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
766            offset: usize,
767            depth: fidl::encoding::Depth,
768        ) -> fidl::Result<()> {
769            encoder.debug_check_bounds::<StateGetWatcherRequest>(offset);
770            // Zero out padding regions. There's no need to apply masks
771            // because the unmasked parts will be overwritten by fields.
772            unsafe {
773                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
774                (ptr as *mut u64).write_unaligned(0);
775            }
776            // Write the fields.
777            self.0.encode(encoder, offset + 0, depth)?;
778            self.1.encode(encoder, offset + 16, depth)?;
779            Ok(())
780        }
781    }
782
783    impl fidl::encoding::Decode<Self, fdomain_client::fidl::FDomainResourceDialect>
784        for StateGetWatcherRequest
785    {
786        #[inline(always)]
787        fn new_empty() -> Self {
788            Self {
789                options: fidl::new_empty!(
790                    WatcherOptions,
791                    fdomain_client::fidl::FDomainResourceDialect
792                ),
793                watcher: fidl::new_empty!(
794                    fidl::encoding::Endpoint<fdomain_client::fidl::ServerEnd<WatcherMarker>>,
795                    fdomain_client::fidl::FDomainResourceDialect
796                ),
797            }
798        }
799
800        #[inline]
801        unsafe fn decode(
802            &mut self,
803            decoder: &mut fidl::encoding::Decoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
804            offset: usize,
805            _depth: fidl::encoding::Depth,
806        ) -> fidl::Result<()> {
807            decoder.debug_check_bounds::<Self>(offset);
808            // Verify that padding bytes are zero.
809            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
810            let padval = unsafe { (ptr as *const u64).read_unaligned() };
811            let mask = 0xffffffff00000000u64;
812            let maskedval = padval & mask;
813            if maskedval != 0 {
814                return Err(fidl::Error::NonZeroPadding {
815                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
816                });
817            }
818            fidl::decode!(
819                WatcherOptions,
820                fdomain_client::fidl::FDomainResourceDialect,
821                &mut self.options,
822                decoder,
823                offset + 0,
824                _depth
825            )?;
826            fidl::decode!(
827                fidl::encoding::Endpoint<fdomain_client::fidl::ServerEnd<WatcherMarker>>,
828                fdomain_client::fidl::FDomainResourceDialect,
829                &mut self.watcher,
830                decoder,
831                offset + 16,
832                _depth
833            )?;
834            Ok(())
835        }
836    }
837}