Skip to main content

fidl_fuchsia_net_name/
fidl_fuchsia_net_name.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_net_name__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DnsServerWatcherMarker;
16
17impl fidl::endpoints::ProtocolMarker for DnsServerWatcherMarker {
18    type Proxy = DnsServerWatcherProxy;
19    type RequestStream = DnsServerWatcherRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DnsServerWatcherSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.net.name.DnsServerWatcher";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DnsServerWatcherMarker {}
26
27pub trait DnsServerWatcherProxyInterface: Send + Sync {
28    type WatchServersResponseFut: std::future::Future<Output = Result<Vec<DnsServer_>, fidl::Error>>
29        + Send;
30    fn r#watch_servers(&self) -> Self::WatchServersResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct DnsServerWatcherSynchronousProxy {
35    client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for DnsServerWatcherSynchronousProxy {
40    type Proxy = DnsServerWatcherProxy;
41    type Protocol = DnsServerWatcherMarker;
42
43    fn from_channel(inner: fidl::Channel) -> Self {
44        Self::new(inner)
45    }
46
47    fn into_channel(self) -> fidl::Channel {
48        self.client.into_channel()
49    }
50
51    fn as_channel(&self) -> &fidl::Channel {
52        self.client.as_channel()
53    }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl DnsServerWatcherSynchronousProxy {
58    pub fn new(channel: fidl::Channel) -> Self {
59        Self { client: fidl::client::sync::Client::new(channel) }
60    }
61
62    pub fn into_channel(self) -> fidl::Channel {
63        self.client.into_channel()
64    }
65
66    /// Waits until an event arrives and returns it. It is safe for other
67    /// threads to make concurrent requests while waiting for an event.
68    pub fn wait_for_event(
69        &self,
70        deadline: zx::MonotonicInstant,
71    ) -> Result<DnsServerWatcherEvent, fidl::Error> {
72        DnsServerWatcherEvent::decode(
73            self.client.wait_for_event::<DnsServerWatcherMarker>(deadline)?,
74        )
75    }
76
77    /// Returns a list of DNS servers.
78    ///
79    /// First call always returns a snapshot of the current list of servers or blocks if an empty
80    /// list would be returned. Subsequent calls will block until the list of servers changes.
81    ///
82    /// The list of servers changes over time by configuration or network topology changes,
83    /// expiration, etc. Callers must repeatedly call `WatchServers` and replace any previously
84    /// returned `servers` with new ones to avoid using stale or expired entries.
85    ///
86    /// It is invalid to call this method while a previous call is pending. Doing so will cause the
87    /// server end of the protocol to be closed.
88    ///
89    /// - response `servers` The list of servers to use for DNS resolution, in priority order.
90    pub fn r#watch_servers(
91        &self,
92        ___deadline: zx::MonotonicInstant,
93    ) -> Result<Vec<DnsServer_>, fidl::Error> {
94        let _response = self.client.send_query::<
95            fidl::encoding::EmptyPayload,
96            DnsServerWatcherWatchServersResponse,
97            DnsServerWatcherMarker,
98        >(
99            (),
100            0x5748907e7f11b632,
101            fidl::encoding::DynamicFlags::empty(),
102            ___deadline,
103        )?;
104        Ok(_response.servers)
105    }
106}
107
108#[cfg(target_os = "fuchsia")]
109impl From<DnsServerWatcherSynchronousProxy> for zx::NullableHandle {
110    fn from(value: DnsServerWatcherSynchronousProxy) -> Self {
111        value.into_channel().into()
112    }
113}
114
115#[cfg(target_os = "fuchsia")]
116impl From<fidl::Channel> for DnsServerWatcherSynchronousProxy {
117    fn from(value: fidl::Channel) -> Self {
118        Self::new(value)
119    }
120}
121
122#[cfg(target_os = "fuchsia")]
123impl fidl::endpoints::FromClient for DnsServerWatcherSynchronousProxy {
124    type Protocol = DnsServerWatcherMarker;
125
126    fn from_client(value: fidl::endpoints::ClientEnd<DnsServerWatcherMarker>) -> Self {
127        Self::new(value.into_channel())
128    }
129}
130
131#[derive(Debug, Clone)]
132pub struct DnsServerWatcherProxy {
133    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
134}
135
136impl fidl::endpoints::Proxy for DnsServerWatcherProxy {
137    type Protocol = DnsServerWatcherMarker;
138
139    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
140        Self::new(inner)
141    }
142
143    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
144        self.client.into_channel().map_err(|client| Self { client })
145    }
146
147    fn as_channel(&self) -> &::fidl::AsyncChannel {
148        self.client.as_channel()
149    }
150}
151
152impl DnsServerWatcherProxy {
153    /// Create a new Proxy for fuchsia.net.name/DnsServerWatcher.
154    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
155        let protocol_name = <DnsServerWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
156        Self { client: fidl::client::Client::new(channel, protocol_name) }
157    }
158
159    /// Get a Stream of events from the remote end of the protocol.
160    ///
161    /// # Panics
162    ///
163    /// Panics if the event stream was already taken.
164    pub fn take_event_stream(&self) -> DnsServerWatcherEventStream {
165        DnsServerWatcherEventStream { event_receiver: self.client.take_event_receiver() }
166    }
167
168    /// Returns a list of DNS servers.
169    ///
170    /// First call always returns a snapshot of the current list of servers or blocks if an empty
171    /// list would be returned. Subsequent calls will block until the list of servers changes.
172    ///
173    /// The list of servers changes over time by configuration or network topology changes,
174    /// expiration, etc. Callers must repeatedly call `WatchServers` and replace any previously
175    /// returned `servers` with new ones to avoid using stale or expired entries.
176    ///
177    /// It is invalid to call this method while a previous call is pending. Doing so will cause the
178    /// server end of the protocol to be closed.
179    ///
180    /// - response `servers` The list of servers to use for DNS resolution, in priority order.
181    pub fn r#watch_servers(
182        &self,
183    ) -> fidl::client::QueryResponseFut<
184        Vec<DnsServer_>,
185        fidl::encoding::DefaultFuchsiaResourceDialect,
186    > {
187        DnsServerWatcherProxyInterface::r#watch_servers(self)
188    }
189}
190
191impl DnsServerWatcherProxyInterface for DnsServerWatcherProxy {
192    type WatchServersResponseFut = fidl::client::QueryResponseFut<
193        Vec<DnsServer_>,
194        fidl::encoding::DefaultFuchsiaResourceDialect,
195    >;
196    fn r#watch_servers(&self) -> Self::WatchServersResponseFut {
197        fn _decode(
198            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
199        ) -> Result<Vec<DnsServer_>, fidl::Error> {
200            let _response = fidl::client::decode_transaction_body::<
201                DnsServerWatcherWatchServersResponse,
202                fidl::encoding::DefaultFuchsiaResourceDialect,
203                0x5748907e7f11b632,
204            >(_buf?)?;
205            Ok(_response.servers)
206        }
207        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Vec<DnsServer_>>(
208            (),
209            0x5748907e7f11b632,
210            fidl::encoding::DynamicFlags::empty(),
211            _decode,
212        )
213    }
214}
215
216pub struct DnsServerWatcherEventStream {
217    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
218}
219
220impl std::marker::Unpin for DnsServerWatcherEventStream {}
221
222impl futures::stream::FusedStream for DnsServerWatcherEventStream {
223    fn is_terminated(&self) -> bool {
224        self.event_receiver.is_terminated()
225    }
226}
227
228impl futures::Stream for DnsServerWatcherEventStream {
229    type Item = Result<DnsServerWatcherEvent, fidl::Error>;
230
231    fn poll_next(
232        mut self: std::pin::Pin<&mut Self>,
233        cx: &mut std::task::Context<'_>,
234    ) -> std::task::Poll<Option<Self::Item>> {
235        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
236            &mut self.event_receiver,
237            cx
238        )?) {
239            Some(buf) => std::task::Poll::Ready(Some(DnsServerWatcherEvent::decode(buf))),
240            None => std::task::Poll::Ready(None),
241        }
242    }
243}
244
245#[derive(Debug)]
246pub enum DnsServerWatcherEvent {}
247
248impl DnsServerWatcherEvent {
249    /// Decodes a message buffer as a [`DnsServerWatcherEvent`].
250    fn decode(
251        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
252    ) -> Result<DnsServerWatcherEvent, fidl::Error> {
253        let (bytes, _handles) = buf.split_mut();
254        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
255        debug_assert_eq!(tx_header.tx_id, 0);
256        match tx_header.ordinal {
257            _ => Err(fidl::Error::UnknownOrdinal {
258                ordinal: tx_header.ordinal,
259                protocol_name:
260                    <DnsServerWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
261            }),
262        }
263    }
264}
265
266/// A Stream of incoming requests for fuchsia.net.name/DnsServerWatcher.
267pub struct DnsServerWatcherRequestStream {
268    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
269    is_terminated: bool,
270}
271
272impl std::marker::Unpin for DnsServerWatcherRequestStream {}
273
274impl futures::stream::FusedStream for DnsServerWatcherRequestStream {
275    fn is_terminated(&self) -> bool {
276        self.is_terminated
277    }
278}
279
280impl fidl::endpoints::RequestStream for DnsServerWatcherRequestStream {
281    type Protocol = DnsServerWatcherMarker;
282    type ControlHandle = DnsServerWatcherControlHandle;
283
284    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
285        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
286    }
287
288    fn control_handle(&self) -> Self::ControlHandle {
289        DnsServerWatcherControlHandle { inner: self.inner.clone() }
290    }
291
292    fn into_inner(
293        self,
294    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
295    {
296        (self.inner, self.is_terminated)
297    }
298
299    fn from_inner(
300        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
301        is_terminated: bool,
302    ) -> Self {
303        Self { inner, is_terminated }
304    }
305}
306
307impl futures::Stream for DnsServerWatcherRequestStream {
308    type Item = Result<DnsServerWatcherRequest, fidl::Error>;
309
310    fn poll_next(
311        mut self: std::pin::Pin<&mut Self>,
312        cx: &mut std::task::Context<'_>,
313    ) -> std::task::Poll<Option<Self::Item>> {
314        let this = &mut *self;
315        if this.inner.check_shutdown(cx) {
316            this.is_terminated = true;
317            return std::task::Poll::Ready(None);
318        }
319        if this.is_terminated {
320            panic!("polled DnsServerWatcherRequestStream after completion");
321        }
322        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
323            |bytes, handles| {
324                match this.inner.channel().read_etc(cx, bytes, handles) {
325                    std::task::Poll::Ready(Ok(())) => {}
326                    std::task::Poll::Pending => return std::task::Poll::Pending,
327                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
328                        this.is_terminated = true;
329                        return std::task::Poll::Ready(None);
330                    }
331                    std::task::Poll::Ready(Err(e)) => {
332                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
333                            e.into(),
334                        ))));
335                    }
336                }
337
338                // A message has been received from the channel
339                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
340
341                std::task::Poll::Ready(Some(match header.ordinal {
342                    0x5748907e7f11b632 => {
343                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
344                        let mut req = fidl::new_empty!(
345                            fidl::encoding::EmptyPayload,
346                            fidl::encoding::DefaultFuchsiaResourceDialect
347                        );
348                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
349                        let control_handle =
350                            DnsServerWatcherControlHandle { inner: this.inner.clone() };
351                        Ok(DnsServerWatcherRequest::WatchServers {
352                            responder: DnsServerWatcherWatchServersResponder {
353                                control_handle: std::mem::ManuallyDrop::new(control_handle),
354                                tx_id: header.tx_id,
355                            },
356                        })
357                    }
358                    _ => Err(fidl::Error::UnknownOrdinal {
359                        ordinal: header.ordinal,
360                        protocol_name:
361                            <DnsServerWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
362                    }),
363                }))
364            },
365        )
366    }
367}
368
369/// Provides a hanging get interface to watch for DNS servers configuration.
370#[derive(Debug)]
371pub enum DnsServerWatcherRequest {
372    /// Returns a list of DNS servers.
373    ///
374    /// First call always returns a snapshot of the current list of servers or blocks if an empty
375    /// list would be returned. Subsequent calls will block until the list of servers changes.
376    ///
377    /// The list of servers changes over time by configuration or network topology changes,
378    /// expiration, etc. Callers must repeatedly call `WatchServers` and replace any previously
379    /// returned `servers` with new ones to avoid using stale or expired entries.
380    ///
381    /// It is invalid to call this method while a previous call is pending. Doing so will cause the
382    /// server end of the protocol to be closed.
383    ///
384    /// - response `servers` The list of servers to use for DNS resolution, in priority order.
385    WatchServers { responder: DnsServerWatcherWatchServersResponder },
386}
387
388impl DnsServerWatcherRequest {
389    #[allow(irrefutable_let_patterns)]
390    pub fn into_watch_servers(self) -> Option<(DnsServerWatcherWatchServersResponder)> {
391        if let DnsServerWatcherRequest::WatchServers { responder } = self {
392            Some((responder))
393        } else {
394            None
395        }
396    }
397
398    /// Name of the method defined in FIDL
399    pub fn method_name(&self) -> &'static str {
400        match *self {
401            DnsServerWatcherRequest::WatchServers { .. } => "watch_servers",
402        }
403    }
404}
405
406#[derive(Debug, Clone)]
407pub struct DnsServerWatcherControlHandle {
408    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
409}
410
411impl fidl::endpoints::ControlHandle for DnsServerWatcherControlHandle {
412    fn shutdown(&self) {
413        self.inner.shutdown()
414    }
415
416    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
417        self.inner.shutdown_with_epitaph(status)
418    }
419
420    fn is_closed(&self) -> bool {
421        self.inner.channel().is_closed()
422    }
423    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
424        self.inner.channel().on_closed()
425    }
426
427    #[cfg(target_os = "fuchsia")]
428    fn signal_peer(
429        &self,
430        clear_mask: zx::Signals,
431        set_mask: zx::Signals,
432    ) -> Result<(), zx_status::Status> {
433        use fidl::Peered;
434        self.inner.channel().signal_peer(clear_mask, set_mask)
435    }
436}
437
438impl DnsServerWatcherControlHandle {}
439
440#[must_use = "FIDL methods require a response to be sent"]
441#[derive(Debug)]
442pub struct DnsServerWatcherWatchServersResponder {
443    control_handle: std::mem::ManuallyDrop<DnsServerWatcherControlHandle>,
444    tx_id: u32,
445}
446
447/// Set the the channel to be shutdown (see [`DnsServerWatcherControlHandle::shutdown`])
448/// if the responder is dropped without sending a response, so that the client
449/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
450impl std::ops::Drop for DnsServerWatcherWatchServersResponder {
451    fn drop(&mut self) {
452        self.control_handle.shutdown();
453        // Safety: drops once, never accessed again
454        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
455    }
456}
457
458impl fidl::endpoints::Responder for DnsServerWatcherWatchServersResponder {
459    type ControlHandle = DnsServerWatcherControlHandle;
460
461    fn control_handle(&self) -> &DnsServerWatcherControlHandle {
462        &self.control_handle
463    }
464
465    fn drop_without_shutdown(mut self) {
466        // Safety: drops once, never accessed again due to mem::forget
467        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
468        // Prevent Drop from running (which would shut down the channel)
469        std::mem::forget(self);
470    }
471}
472
473impl DnsServerWatcherWatchServersResponder {
474    /// Sends a response to the FIDL transaction.
475    ///
476    /// Sets the channel to shutdown if an error occurs.
477    pub fn send(self, mut servers: &[DnsServer_]) -> Result<(), fidl::Error> {
478        let _result = self.send_raw(servers);
479        if _result.is_err() {
480            self.control_handle.shutdown();
481        }
482        self.drop_without_shutdown();
483        _result
484    }
485
486    /// Similar to "send" but does not shutdown the channel if an error occurs.
487    pub fn send_no_shutdown_on_err(self, mut servers: &[DnsServer_]) -> Result<(), fidl::Error> {
488        let _result = self.send_raw(servers);
489        self.drop_without_shutdown();
490        _result
491    }
492
493    fn send_raw(&self, mut servers: &[DnsServer_]) -> Result<(), fidl::Error> {
494        self.control_handle.inner.send::<DnsServerWatcherWatchServersResponse>(
495            (servers,),
496            self.tx_id,
497            0x5748907e7f11b632,
498            fidl::encoding::DynamicFlags::empty(),
499        )
500    }
501}
502
503#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
504pub struct LookupMarker;
505
506impl fidl::endpoints::ProtocolMarker for LookupMarker {
507    type Proxy = LookupProxy;
508    type RequestStream = LookupRequestStream;
509    #[cfg(target_os = "fuchsia")]
510    type SynchronousProxy = LookupSynchronousProxy;
511
512    const DEBUG_NAME: &'static str = "fuchsia.net.name.Lookup";
513}
514impl fidl::endpoints::DiscoverableProtocolMarker for LookupMarker {}
515pub type LookupLookupIpResult = Result<LookupResult, LookupError>;
516pub type LookupLookupHostnameResult = Result<String, LookupError>;
517
518pub trait LookupProxyInterface: Send + Sync {
519    type LookupIpResponseFut: std::future::Future<Output = Result<LookupLookupIpResult, fidl::Error>>
520        + Send;
521    fn r#lookup_ip(&self, hostname: &str, options: &LookupIpOptions) -> Self::LookupIpResponseFut;
522    type LookupHostnameResponseFut: std::future::Future<Output = Result<LookupLookupHostnameResult, fidl::Error>>
523        + Send;
524    fn r#lookup_hostname(
525        &self,
526        addr: &fidl_fuchsia_net::IpAddress,
527    ) -> Self::LookupHostnameResponseFut;
528}
529#[derive(Debug)]
530#[cfg(target_os = "fuchsia")]
531pub struct LookupSynchronousProxy {
532    client: fidl::client::sync::Client,
533}
534
535#[cfg(target_os = "fuchsia")]
536impl fidl::endpoints::SynchronousProxy for LookupSynchronousProxy {
537    type Proxy = LookupProxy;
538    type Protocol = LookupMarker;
539
540    fn from_channel(inner: fidl::Channel) -> Self {
541        Self::new(inner)
542    }
543
544    fn into_channel(self) -> fidl::Channel {
545        self.client.into_channel()
546    }
547
548    fn as_channel(&self) -> &fidl::Channel {
549        self.client.as_channel()
550    }
551}
552
553#[cfg(target_os = "fuchsia")]
554impl LookupSynchronousProxy {
555    pub fn new(channel: fidl::Channel) -> Self {
556        Self { client: fidl::client::sync::Client::new(channel) }
557    }
558
559    pub fn into_channel(self) -> fidl::Channel {
560        self.client.into_channel()
561    }
562
563    /// Waits until an event arrives and returns it. It is safe for other
564    /// threads to make concurrent requests while waiting for an event.
565    pub fn wait_for_event(
566        &self,
567        deadline: zx::MonotonicInstant,
568    ) -> Result<LookupEvent, fidl::Error> {
569        LookupEvent::decode(self.client.wait_for_event::<LookupMarker>(deadline)?)
570    }
571
572    /// Lookup a list of IP addresses by hostname.
573    pub fn r#lookup_ip(
574        &self,
575        mut hostname: &str,
576        mut options: &LookupIpOptions,
577        ___deadline: zx::MonotonicInstant,
578    ) -> Result<LookupLookupIpResult, fidl::Error> {
579        let _response = self.client.send_query::<
580            LookupLookupIpRequest,
581            fidl::encoding::ResultType<LookupLookupIpResponse, LookupError>,
582            LookupMarker,
583        >(
584            (hostname, options,),
585            0x59247caf7560c1d0,
586            fidl::encoding::DynamicFlags::empty(),
587            ___deadline,
588        )?;
589        Ok(_response.map(|x| x.result))
590    }
591
592    /// Look up a hostname by IP address.
593    pub fn r#lookup_hostname(
594        &self,
595        mut addr: &fidl_fuchsia_net::IpAddress,
596        ___deadline: zx::MonotonicInstant,
597    ) -> Result<LookupLookupHostnameResult, fidl::Error> {
598        let _response = self.client.send_query::<
599            LookupLookupHostnameRequest,
600            fidl::encoding::ResultType<LookupLookupHostnameResponse, LookupError>,
601            LookupMarker,
602        >(
603            (addr,),
604            0x1b456b0e84888324,
605            fidl::encoding::DynamicFlags::empty(),
606            ___deadline,
607        )?;
608        Ok(_response.map(|x| x.hostname))
609    }
610}
611
612#[cfg(target_os = "fuchsia")]
613impl From<LookupSynchronousProxy> for zx::NullableHandle {
614    fn from(value: LookupSynchronousProxy) -> Self {
615        value.into_channel().into()
616    }
617}
618
619#[cfg(target_os = "fuchsia")]
620impl From<fidl::Channel> for LookupSynchronousProxy {
621    fn from(value: fidl::Channel) -> Self {
622        Self::new(value)
623    }
624}
625
626#[cfg(target_os = "fuchsia")]
627impl fidl::endpoints::FromClient for LookupSynchronousProxy {
628    type Protocol = LookupMarker;
629
630    fn from_client(value: fidl::endpoints::ClientEnd<LookupMarker>) -> Self {
631        Self::new(value.into_channel())
632    }
633}
634
635#[derive(Debug, Clone)]
636pub struct LookupProxy {
637    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
638}
639
640impl fidl::endpoints::Proxy for LookupProxy {
641    type Protocol = LookupMarker;
642
643    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
644        Self::new(inner)
645    }
646
647    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
648        self.client.into_channel().map_err(|client| Self { client })
649    }
650
651    fn as_channel(&self) -> &::fidl::AsyncChannel {
652        self.client.as_channel()
653    }
654}
655
656impl LookupProxy {
657    /// Create a new Proxy for fuchsia.net.name/Lookup.
658    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
659        let protocol_name = <LookupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
660        Self { client: fidl::client::Client::new(channel, protocol_name) }
661    }
662
663    /// Get a Stream of events from the remote end of the protocol.
664    ///
665    /// # Panics
666    ///
667    /// Panics if the event stream was already taken.
668    pub fn take_event_stream(&self) -> LookupEventStream {
669        LookupEventStream { event_receiver: self.client.take_event_receiver() }
670    }
671
672    /// Lookup a list of IP addresses by hostname.
673    pub fn r#lookup_ip(
674        &self,
675        mut hostname: &str,
676        mut options: &LookupIpOptions,
677    ) -> fidl::client::QueryResponseFut<
678        LookupLookupIpResult,
679        fidl::encoding::DefaultFuchsiaResourceDialect,
680    > {
681        LookupProxyInterface::r#lookup_ip(self, hostname, options)
682    }
683
684    /// Look up a hostname by IP address.
685    pub fn r#lookup_hostname(
686        &self,
687        mut addr: &fidl_fuchsia_net::IpAddress,
688    ) -> fidl::client::QueryResponseFut<
689        LookupLookupHostnameResult,
690        fidl::encoding::DefaultFuchsiaResourceDialect,
691    > {
692        LookupProxyInterface::r#lookup_hostname(self, addr)
693    }
694}
695
696impl LookupProxyInterface for LookupProxy {
697    type LookupIpResponseFut = fidl::client::QueryResponseFut<
698        LookupLookupIpResult,
699        fidl::encoding::DefaultFuchsiaResourceDialect,
700    >;
701    fn r#lookup_ip(
702        &self,
703        mut hostname: &str,
704        mut options: &LookupIpOptions,
705    ) -> Self::LookupIpResponseFut {
706        fn _decode(
707            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
708        ) -> Result<LookupLookupIpResult, fidl::Error> {
709            let _response = fidl::client::decode_transaction_body::<
710                fidl::encoding::ResultType<LookupLookupIpResponse, LookupError>,
711                fidl::encoding::DefaultFuchsiaResourceDialect,
712                0x59247caf7560c1d0,
713            >(_buf?)?;
714            Ok(_response.map(|x| x.result))
715        }
716        self.client.send_query_and_decode::<LookupLookupIpRequest, LookupLookupIpResult>(
717            (hostname, options),
718            0x59247caf7560c1d0,
719            fidl::encoding::DynamicFlags::empty(),
720            _decode,
721        )
722    }
723
724    type LookupHostnameResponseFut = fidl::client::QueryResponseFut<
725        LookupLookupHostnameResult,
726        fidl::encoding::DefaultFuchsiaResourceDialect,
727    >;
728    fn r#lookup_hostname(
729        &self,
730        mut addr: &fidl_fuchsia_net::IpAddress,
731    ) -> Self::LookupHostnameResponseFut {
732        fn _decode(
733            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
734        ) -> Result<LookupLookupHostnameResult, fidl::Error> {
735            let _response = fidl::client::decode_transaction_body::<
736                fidl::encoding::ResultType<LookupLookupHostnameResponse, LookupError>,
737                fidl::encoding::DefaultFuchsiaResourceDialect,
738                0x1b456b0e84888324,
739            >(_buf?)?;
740            Ok(_response.map(|x| x.hostname))
741        }
742        self.client
743            .send_query_and_decode::<LookupLookupHostnameRequest, LookupLookupHostnameResult>(
744                (addr,),
745                0x1b456b0e84888324,
746                fidl::encoding::DynamicFlags::empty(),
747                _decode,
748            )
749    }
750}
751
752pub struct LookupEventStream {
753    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
754}
755
756impl std::marker::Unpin for LookupEventStream {}
757
758impl futures::stream::FusedStream for LookupEventStream {
759    fn is_terminated(&self) -> bool {
760        self.event_receiver.is_terminated()
761    }
762}
763
764impl futures::Stream for LookupEventStream {
765    type Item = Result<LookupEvent, fidl::Error>;
766
767    fn poll_next(
768        mut self: std::pin::Pin<&mut Self>,
769        cx: &mut std::task::Context<'_>,
770    ) -> std::task::Poll<Option<Self::Item>> {
771        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
772            &mut self.event_receiver,
773            cx
774        )?) {
775            Some(buf) => std::task::Poll::Ready(Some(LookupEvent::decode(buf))),
776            None => std::task::Poll::Ready(None),
777        }
778    }
779}
780
781#[derive(Debug)]
782pub enum LookupEvent {}
783
784impl LookupEvent {
785    /// Decodes a message buffer as a [`LookupEvent`].
786    fn decode(
787        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
788    ) -> Result<LookupEvent, fidl::Error> {
789        let (bytes, _handles) = buf.split_mut();
790        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
791        debug_assert_eq!(tx_header.tx_id, 0);
792        match tx_header.ordinal {
793            _ => Err(fidl::Error::UnknownOrdinal {
794                ordinal: tx_header.ordinal,
795                protocol_name: <LookupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
796            }),
797        }
798    }
799}
800
801/// A Stream of incoming requests for fuchsia.net.name/Lookup.
802pub struct LookupRequestStream {
803    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
804    is_terminated: bool,
805}
806
807impl std::marker::Unpin for LookupRequestStream {}
808
809impl futures::stream::FusedStream for LookupRequestStream {
810    fn is_terminated(&self) -> bool {
811        self.is_terminated
812    }
813}
814
815impl fidl::endpoints::RequestStream for LookupRequestStream {
816    type Protocol = LookupMarker;
817    type ControlHandle = LookupControlHandle;
818
819    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
820        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
821    }
822
823    fn control_handle(&self) -> Self::ControlHandle {
824        LookupControlHandle { inner: self.inner.clone() }
825    }
826
827    fn into_inner(
828        self,
829    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
830    {
831        (self.inner, self.is_terminated)
832    }
833
834    fn from_inner(
835        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
836        is_terminated: bool,
837    ) -> Self {
838        Self { inner, is_terminated }
839    }
840}
841
842impl futures::Stream for LookupRequestStream {
843    type Item = Result<LookupRequest, fidl::Error>;
844
845    fn poll_next(
846        mut self: std::pin::Pin<&mut Self>,
847        cx: &mut std::task::Context<'_>,
848    ) -> std::task::Poll<Option<Self::Item>> {
849        let this = &mut *self;
850        if this.inner.check_shutdown(cx) {
851            this.is_terminated = true;
852            return std::task::Poll::Ready(None);
853        }
854        if this.is_terminated {
855            panic!("polled LookupRequestStream after completion");
856        }
857        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
858            |bytes, handles| {
859                match this.inner.channel().read_etc(cx, bytes, handles) {
860                    std::task::Poll::Ready(Ok(())) => {}
861                    std::task::Poll::Pending => return std::task::Poll::Pending,
862                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
863                        this.is_terminated = true;
864                        return std::task::Poll::Ready(None);
865                    }
866                    std::task::Poll::Ready(Err(e)) => {
867                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
868                            e.into(),
869                        ))));
870                    }
871                }
872
873                // A message has been received from the channel
874                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
875
876                std::task::Poll::Ready(Some(match header.ordinal {
877                    0x59247caf7560c1d0 => {
878                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
879                        let mut req = fidl::new_empty!(
880                            LookupLookupIpRequest,
881                            fidl::encoding::DefaultFuchsiaResourceDialect
882                        );
883                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<LookupLookupIpRequest>(&header, _body_bytes, handles, &mut req)?;
884                        let control_handle = LookupControlHandle { inner: this.inner.clone() };
885                        Ok(LookupRequest::LookupIp {
886                            hostname: req.hostname,
887                            options: req.options,
888
889                            responder: LookupLookupIpResponder {
890                                control_handle: std::mem::ManuallyDrop::new(control_handle),
891                                tx_id: header.tx_id,
892                            },
893                        })
894                    }
895                    0x1b456b0e84888324 => {
896                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
897                        let mut req = fidl::new_empty!(
898                            LookupLookupHostnameRequest,
899                            fidl::encoding::DefaultFuchsiaResourceDialect
900                        );
901                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<LookupLookupHostnameRequest>(&header, _body_bytes, handles, &mut req)?;
902                        let control_handle = LookupControlHandle { inner: this.inner.clone() };
903                        Ok(LookupRequest::LookupHostname {
904                            addr: req.addr,
905
906                            responder: LookupLookupHostnameResponder {
907                                control_handle: std::mem::ManuallyDrop::new(control_handle),
908                                tx_id: header.tx_id,
909                            },
910                        })
911                    }
912                    _ => Err(fidl::Error::UnknownOrdinal {
913                        ordinal: header.ordinal,
914                        protocol_name:
915                            <LookupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
916                    }),
917                }))
918            },
919        )
920    }
921}
922
923/// Provides name and address resolution.
924#[derive(Debug)]
925pub enum LookupRequest {
926    /// Lookup a list of IP addresses by hostname.
927    LookupIp { hostname: String, options: LookupIpOptions, responder: LookupLookupIpResponder },
928    /// Look up a hostname by IP address.
929    LookupHostname { addr: fidl_fuchsia_net::IpAddress, responder: LookupLookupHostnameResponder },
930}
931
932impl LookupRequest {
933    #[allow(irrefutable_let_patterns)]
934    pub fn into_lookup_ip(self) -> Option<(String, LookupIpOptions, LookupLookupIpResponder)> {
935        if let LookupRequest::LookupIp { hostname, options, responder } = self {
936            Some((hostname, options, responder))
937        } else {
938            None
939        }
940    }
941
942    #[allow(irrefutable_let_patterns)]
943    pub fn into_lookup_hostname(
944        self,
945    ) -> Option<(fidl_fuchsia_net::IpAddress, LookupLookupHostnameResponder)> {
946        if let LookupRequest::LookupHostname { addr, responder } = self {
947            Some((addr, responder))
948        } else {
949            None
950        }
951    }
952
953    /// Name of the method defined in FIDL
954    pub fn method_name(&self) -> &'static str {
955        match *self {
956            LookupRequest::LookupIp { .. } => "lookup_ip",
957            LookupRequest::LookupHostname { .. } => "lookup_hostname",
958        }
959    }
960}
961
962#[derive(Debug, Clone)]
963pub struct LookupControlHandle {
964    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
965}
966
967impl fidl::endpoints::ControlHandle for LookupControlHandle {
968    fn shutdown(&self) {
969        self.inner.shutdown()
970    }
971
972    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
973        self.inner.shutdown_with_epitaph(status)
974    }
975
976    fn is_closed(&self) -> bool {
977        self.inner.channel().is_closed()
978    }
979    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
980        self.inner.channel().on_closed()
981    }
982
983    #[cfg(target_os = "fuchsia")]
984    fn signal_peer(
985        &self,
986        clear_mask: zx::Signals,
987        set_mask: zx::Signals,
988    ) -> Result<(), zx_status::Status> {
989        use fidl::Peered;
990        self.inner.channel().signal_peer(clear_mask, set_mask)
991    }
992}
993
994impl LookupControlHandle {}
995
996#[must_use = "FIDL methods require a response to be sent"]
997#[derive(Debug)]
998pub struct LookupLookupIpResponder {
999    control_handle: std::mem::ManuallyDrop<LookupControlHandle>,
1000    tx_id: u32,
1001}
1002
1003/// Set the the channel to be shutdown (see [`LookupControlHandle::shutdown`])
1004/// if the responder is dropped without sending a response, so that the client
1005/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1006impl std::ops::Drop for LookupLookupIpResponder {
1007    fn drop(&mut self) {
1008        self.control_handle.shutdown();
1009        // Safety: drops once, never accessed again
1010        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1011    }
1012}
1013
1014impl fidl::endpoints::Responder for LookupLookupIpResponder {
1015    type ControlHandle = LookupControlHandle;
1016
1017    fn control_handle(&self) -> &LookupControlHandle {
1018        &self.control_handle
1019    }
1020
1021    fn drop_without_shutdown(mut self) {
1022        // Safety: drops once, never accessed again due to mem::forget
1023        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1024        // Prevent Drop from running (which would shut down the channel)
1025        std::mem::forget(self);
1026    }
1027}
1028
1029impl LookupLookupIpResponder {
1030    /// Sends a response to the FIDL transaction.
1031    ///
1032    /// Sets the channel to shutdown if an error occurs.
1033    pub fn send(self, mut result: Result<&LookupResult, LookupError>) -> Result<(), fidl::Error> {
1034        let _result = self.send_raw(result);
1035        if _result.is_err() {
1036            self.control_handle.shutdown();
1037        }
1038        self.drop_without_shutdown();
1039        _result
1040    }
1041
1042    /// Similar to "send" but does not shutdown the channel if an error occurs.
1043    pub fn send_no_shutdown_on_err(
1044        self,
1045        mut result: Result<&LookupResult, LookupError>,
1046    ) -> Result<(), fidl::Error> {
1047        let _result = self.send_raw(result);
1048        self.drop_without_shutdown();
1049        _result
1050    }
1051
1052    fn send_raw(&self, mut result: Result<&LookupResult, LookupError>) -> Result<(), fidl::Error> {
1053        self.control_handle
1054            .inner
1055            .send::<fidl::encoding::ResultType<LookupLookupIpResponse, LookupError>>(
1056                result.map(|result| (result,)),
1057                self.tx_id,
1058                0x59247caf7560c1d0,
1059                fidl::encoding::DynamicFlags::empty(),
1060            )
1061    }
1062}
1063
1064#[must_use = "FIDL methods require a response to be sent"]
1065#[derive(Debug)]
1066pub struct LookupLookupHostnameResponder {
1067    control_handle: std::mem::ManuallyDrop<LookupControlHandle>,
1068    tx_id: u32,
1069}
1070
1071/// Set the the channel to be shutdown (see [`LookupControlHandle::shutdown`])
1072/// if the responder is dropped without sending a response, so that the client
1073/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1074impl std::ops::Drop for LookupLookupHostnameResponder {
1075    fn drop(&mut self) {
1076        self.control_handle.shutdown();
1077        // Safety: drops once, never accessed again
1078        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1079    }
1080}
1081
1082impl fidl::endpoints::Responder for LookupLookupHostnameResponder {
1083    type ControlHandle = LookupControlHandle;
1084
1085    fn control_handle(&self) -> &LookupControlHandle {
1086        &self.control_handle
1087    }
1088
1089    fn drop_without_shutdown(mut self) {
1090        // Safety: drops once, never accessed again due to mem::forget
1091        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1092        // Prevent Drop from running (which would shut down the channel)
1093        std::mem::forget(self);
1094    }
1095}
1096
1097impl LookupLookupHostnameResponder {
1098    /// Sends a response to the FIDL transaction.
1099    ///
1100    /// Sets the channel to shutdown if an error occurs.
1101    pub fn send(self, mut result: Result<&str, LookupError>) -> Result<(), fidl::Error> {
1102        let _result = self.send_raw(result);
1103        if _result.is_err() {
1104            self.control_handle.shutdown();
1105        }
1106        self.drop_without_shutdown();
1107        _result
1108    }
1109
1110    /// Similar to "send" but does not shutdown the channel if an error occurs.
1111    pub fn send_no_shutdown_on_err(
1112        self,
1113        mut result: Result<&str, LookupError>,
1114    ) -> Result<(), fidl::Error> {
1115        let _result = self.send_raw(result);
1116        self.drop_without_shutdown();
1117        _result
1118    }
1119
1120    fn send_raw(&self, mut result: Result<&str, LookupError>) -> Result<(), fidl::Error> {
1121        self.control_handle.inner.send::<fidl::encoding::ResultType<
1122            LookupLookupHostnameResponse,
1123            LookupError,
1124        >>(
1125            result.map(|hostname| (hostname,)),
1126            self.tx_id,
1127            0x1b456b0e84888324,
1128            fidl::encoding::DynamicFlags::empty(),
1129        )
1130    }
1131}
1132
1133#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1134pub struct LookupAdminMarker;
1135
1136impl fidl::endpoints::ProtocolMarker for LookupAdminMarker {
1137    type Proxy = LookupAdminProxy;
1138    type RequestStream = LookupAdminRequestStream;
1139    #[cfg(target_os = "fuchsia")]
1140    type SynchronousProxy = LookupAdminSynchronousProxy;
1141
1142    const DEBUG_NAME: &'static str = "fuchsia.net.name.LookupAdmin";
1143}
1144impl fidl::endpoints::DiscoverableProtocolMarker for LookupAdminMarker {}
1145pub type LookupAdminSetDnsServersResult = Result<(), i32>;
1146
1147pub trait LookupAdminProxyInterface: Send + Sync {
1148    type SetDnsServersResponseFut: std::future::Future<Output = Result<LookupAdminSetDnsServersResult, fidl::Error>>
1149        + Send;
1150    fn r#set_dns_servers(
1151        &self,
1152        servers: &[fidl_fuchsia_net::SocketAddress],
1153    ) -> Self::SetDnsServersResponseFut;
1154    type GetDnsServersResponseFut: std::future::Future<Output = Result<Vec<fidl_fuchsia_net::SocketAddress>, fidl::Error>>
1155        + Send;
1156    fn r#get_dns_servers(&self) -> Self::GetDnsServersResponseFut;
1157}
1158#[derive(Debug)]
1159#[cfg(target_os = "fuchsia")]
1160pub struct LookupAdminSynchronousProxy {
1161    client: fidl::client::sync::Client,
1162}
1163
1164#[cfg(target_os = "fuchsia")]
1165impl fidl::endpoints::SynchronousProxy for LookupAdminSynchronousProxy {
1166    type Proxy = LookupAdminProxy;
1167    type Protocol = LookupAdminMarker;
1168
1169    fn from_channel(inner: fidl::Channel) -> Self {
1170        Self::new(inner)
1171    }
1172
1173    fn into_channel(self) -> fidl::Channel {
1174        self.client.into_channel()
1175    }
1176
1177    fn as_channel(&self) -> &fidl::Channel {
1178        self.client.as_channel()
1179    }
1180}
1181
1182#[cfg(target_os = "fuchsia")]
1183impl LookupAdminSynchronousProxy {
1184    pub fn new(channel: fidl::Channel) -> Self {
1185        Self { client: fidl::client::sync::Client::new(channel) }
1186    }
1187
1188    pub fn into_channel(self) -> fidl::Channel {
1189        self.client.into_channel()
1190    }
1191
1192    /// Waits until an event arrives and returns it. It is safe for other
1193    /// threads to make concurrent requests while waiting for an event.
1194    pub fn wait_for_event(
1195        &self,
1196        deadline: zx::MonotonicInstant,
1197    ) -> Result<LookupAdminEvent, fidl::Error> {
1198        LookupAdminEvent::decode(self.client.wait_for_event::<LookupAdminMarker>(deadline)?)
1199    }
1200
1201    /// Sets the DNS servers to `servers`
1202    ///
1203    /// + request `servers` The list of servers to use for domain name resolution, in priority
1204    /// order. An empty list means no servers will be used and name resolution may fail. Each
1205    /// `SocketAddress` in `servers` must be a valid unicast socket address. The list of servers
1206    /// will be deduplicated.
1207    /// * error Returns `ZX_ERR_INVALID_ARGS` if any of the provided addresses does not meet the
1208    /// conditions above.
1209    pub fn r#set_dns_servers(
1210        &self,
1211        mut servers: &[fidl_fuchsia_net::SocketAddress],
1212        ___deadline: zx::MonotonicInstant,
1213    ) -> Result<LookupAdminSetDnsServersResult, fidl::Error> {
1214        let _response = self.client.send_query::<
1215            LookupAdminSetDnsServersRequest,
1216            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1217            LookupAdminMarker,
1218        >(
1219            (servers,),
1220            0x55e2b9fcc777be96,
1221            fidl::encoding::DynamicFlags::empty(),
1222            ___deadline,
1223        )?;
1224        Ok(_response.map(|x| x))
1225    }
1226
1227    /// Gets the DNS servers currently in use to resolve name lookups.
1228    /// - response `servers` The list of servers in use by `LookupAdmin`, in priority order.
1229    pub fn r#get_dns_servers(
1230        &self,
1231        ___deadline: zx::MonotonicInstant,
1232    ) -> Result<Vec<fidl_fuchsia_net::SocketAddress>, fidl::Error> {
1233        let _response = self.client.send_query::<
1234            fidl::encoding::EmptyPayload,
1235            LookupAdminGetDnsServersResponse,
1236            LookupAdminMarker,
1237        >(
1238            (),
1239            0x614303bf6e72f80f,
1240            fidl::encoding::DynamicFlags::empty(),
1241            ___deadline,
1242        )?;
1243        Ok(_response.servers)
1244    }
1245}
1246
1247#[cfg(target_os = "fuchsia")]
1248impl From<LookupAdminSynchronousProxy> for zx::NullableHandle {
1249    fn from(value: LookupAdminSynchronousProxy) -> Self {
1250        value.into_channel().into()
1251    }
1252}
1253
1254#[cfg(target_os = "fuchsia")]
1255impl From<fidl::Channel> for LookupAdminSynchronousProxy {
1256    fn from(value: fidl::Channel) -> Self {
1257        Self::new(value)
1258    }
1259}
1260
1261#[cfg(target_os = "fuchsia")]
1262impl fidl::endpoints::FromClient for LookupAdminSynchronousProxy {
1263    type Protocol = LookupAdminMarker;
1264
1265    fn from_client(value: fidl::endpoints::ClientEnd<LookupAdminMarker>) -> Self {
1266        Self::new(value.into_channel())
1267    }
1268}
1269
1270#[derive(Debug, Clone)]
1271pub struct LookupAdminProxy {
1272    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1273}
1274
1275impl fidl::endpoints::Proxy for LookupAdminProxy {
1276    type Protocol = LookupAdminMarker;
1277
1278    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1279        Self::new(inner)
1280    }
1281
1282    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1283        self.client.into_channel().map_err(|client| Self { client })
1284    }
1285
1286    fn as_channel(&self) -> &::fidl::AsyncChannel {
1287        self.client.as_channel()
1288    }
1289}
1290
1291impl LookupAdminProxy {
1292    /// Create a new Proxy for fuchsia.net.name/LookupAdmin.
1293    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1294        let protocol_name = <LookupAdminMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1295        Self { client: fidl::client::Client::new(channel, protocol_name) }
1296    }
1297
1298    /// Get a Stream of events from the remote end of the protocol.
1299    ///
1300    /// # Panics
1301    ///
1302    /// Panics if the event stream was already taken.
1303    pub fn take_event_stream(&self) -> LookupAdminEventStream {
1304        LookupAdminEventStream { event_receiver: self.client.take_event_receiver() }
1305    }
1306
1307    /// Sets the DNS servers to `servers`
1308    ///
1309    /// + request `servers` The list of servers to use for domain name resolution, in priority
1310    /// order. An empty list means no servers will be used and name resolution may fail. Each
1311    /// `SocketAddress` in `servers` must be a valid unicast socket address. The list of servers
1312    /// will be deduplicated.
1313    /// * error Returns `ZX_ERR_INVALID_ARGS` if any of the provided addresses does not meet the
1314    /// conditions above.
1315    pub fn r#set_dns_servers(
1316        &self,
1317        mut servers: &[fidl_fuchsia_net::SocketAddress],
1318    ) -> fidl::client::QueryResponseFut<
1319        LookupAdminSetDnsServersResult,
1320        fidl::encoding::DefaultFuchsiaResourceDialect,
1321    > {
1322        LookupAdminProxyInterface::r#set_dns_servers(self, servers)
1323    }
1324
1325    /// Gets the DNS servers currently in use to resolve name lookups.
1326    /// - response `servers` The list of servers in use by `LookupAdmin`, in priority order.
1327    pub fn r#get_dns_servers(
1328        &self,
1329    ) -> fidl::client::QueryResponseFut<
1330        Vec<fidl_fuchsia_net::SocketAddress>,
1331        fidl::encoding::DefaultFuchsiaResourceDialect,
1332    > {
1333        LookupAdminProxyInterface::r#get_dns_servers(self)
1334    }
1335}
1336
1337impl LookupAdminProxyInterface for LookupAdminProxy {
1338    type SetDnsServersResponseFut = fidl::client::QueryResponseFut<
1339        LookupAdminSetDnsServersResult,
1340        fidl::encoding::DefaultFuchsiaResourceDialect,
1341    >;
1342    fn r#set_dns_servers(
1343        &self,
1344        mut servers: &[fidl_fuchsia_net::SocketAddress],
1345    ) -> Self::SetDnsServersResponseFut {
1346        fn _decode(
1347            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1348        ) -> Result<LookupAdminSetDnsServersResult, fidl::Error> {
1349            let _response = fidl::client::decode_transaction_body::<
1350                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1351                fidl::encoding::DefaultFuchsiaResourceDialect,
1352                0x55e2b9fcc777be96,
1353            >(_buf?)?;
1354            Ok(_response.map(|x| x))
1355        }
1356        self.client.send_query_and_decode::<
1357            LookupAdminSetDnsServersRequest,
1358            LookupAdminSetDnsServersResult,
1359        >(
1360            (servers,),
1361            0x55e2b9fcc777be96,
1362            fidl::encoding::DynamicFlags::empty(),
1363            _decode,
1364        )
1365    }
1366
1367    type GetDnsServersResponseFut = fidl::client::QueryResponseFut<
1368        Vec<fidl_fuchsia_net::SocketAddress>,
1369        fidl::encoding::DefaultFuchsiaResourceDialect,
1370    >;
1371    fn r#get_dns_servers(&self) -> Self::GetDnsServersResponseFut {
1372        fn _decode(
1373            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1374        ) -> Result<Vec<fidl_fuchsia_net::SocketAddress>, fidl::Error> {
1375            let _response = fidl::client::decode_transaction_body::<
1376                LookupAdminGetDnsServersResponse,
1377                fidl::encoding::DefaultFuchsiaResourceDialect,
1378                0x614303bf6e72f80f,
1379            >(_buf?)?;
1380            Ok(_response.servers)
1381        }
1382        self.client.send_query_and_decode::<
1383            fidl::encoding::EmptyPayload,
1384            Vec<fidl_fuchsia_net::SocketAddress>,
1385        >(
1386            (),
1387            0x614303bf6e72f80f,
1388            fidl::encoding::DynamicFlags::empty(),
1389            _decode,
1390        )
1391    }
1392}
1393
1394pub struct LookupAdminEventStream {
1395    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1396}
1397
1398impl std::marker::Unpin for LookupAdminEventStream {}
1399
1400impl futures::stream::FusedStream for LookupAdminEventStream {
1401    fn is_terminated(&self) -> bool {
1402        self.event_receiver.is_terminated()
1403    }
1404}
1405
1406impl futures::Stream for LookupAdminEventStream {
1407    type Item = Result<LookupAdminEvent, fidl::Error>;
1408
1409    fn poll_next(
1410        mut self: std::pin::Pin<&mut Self>,
1411        cx: &mut std::task::Context<'_>,
1412    ) -> std::task::Poll<Option<Self::Item>> {
1413        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1414            &mut self.event_receiver,
1415            cx
1416        )?) {
1417            Some(buf) => std::task::Poll::Ready(Some(LookupAdminEvent::decode(buf))),
1418            None => std::task::Poll::Ready(None),
1419        }
1420    }
1421}
1422
1423#[derive(Debug)]
1424pub enum LookupAdminEvent {}
1425
1426impl LookupAdminEvent {
1427    /// Decodes a message buffer as a [`LookupAdminEvent`].
1428    fn decode(
1429        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1430    ) -> Result<LookupAdminEvent, fidl::Error> {
1431        let (bytes, _handles) = buf.split_mut();
1432        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1433        debug_assert_eq!(tx_header.tx_id, 0);
1434        match tx_header.ordinal {
1435            _ => Err(fidl::Error::UnknownOrdinal {
1436                ordinal: tx_header.ordinal,
1437                protocol_name: <LookupAdminMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1438            }),
1439        }
1440    }
1441}
1442
1443/// A Stream of incoming requests for fuchsia.net.name/LookupAdmin.
1444pub struct LookupAdminRequestStream {
1445    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1446    is_terminated: bool,
1447}
1448
1449impl std::marker::Unpin for LookupAdminRequestStream {}
1450
1451impl futures::stream::FusedStream for LookupAdminRequestStream {
1452    fn is_terminated(&self) -> bool {
1453        self.is_terminated
1454    }
1455}
1456
1457impl fidl::endpoints::RequestStream for LookupAdminRequestStream {
1458    type Protocol = LookupAdminMarker;
1459    type ControlHandle = LookupAdminControlHandle;
1460
1461    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1462        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1463    }
1464
1465    fn control_handle(&self) -> Self::ControlHandle {
1466        LookupAdminControlHandle { inner: self.inner.clone() }
1467    }
1468
1469    fn into_inner(
1470        self,
1471    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1472    {
1473        (self.inner, self.is_terminated)
1474    }
1475
1476    fn from_inner(
1477        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1478        is_terminated: bool,
1479    ) -> Self {
1480        Self { inner, is_terminated }
1481    }
1482}
1483
1484impl futures::Stream for LookupAdminRequestStream {
1485    type Item = Result<LookupAdminRequest, fidl::Error>;
1486
1487    fn poll_next(
1488        mut self: std::pin::Pin<&mut Self>,
1489        cx: &mut std::task::Context<'_>,
1490    ) -> std::task::Poll<Option<Self::Item>> {
1491        let this = &mut *self;
1492        if this.inner.check_shutdown(cx) {
1493            this.is_terminated = true;
1494            return std::task::Poll::Ready(None);
1495        }
1496        if this.is_terminated {
1497            panic!("polled LookupAdminRequestStream after completion");
1498        }
1499        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1500            |bytes, handles| {
1501                match this.inner.channel().read_etc(cx, bytes, handles) {
1502                    std::task::Poll::Ready(Ok(())) => {}
1503                    std::task::Poll::Pending => return std::task::Poll::Pending,
1504                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1505                        this.is_terminated = true;
1506                        return std::task::Poll::Ready(None);
1507                    }
1508                    std::task::Poll::Ready(Err(e)) => {
1509                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1510                            e.into(),
1511                        ))));
1512                    }
1513                }
1514
1515                // A message has been received from the channel
1516                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1517
1518                std::task::Poll::Ready(Some(match header.ordinal {
1519                    0x55e2b9fcc777be96 => {
1520                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1521                        let mut req = fidl::new_empty!(
1522                            LookupAdminSetDnsServersRequest,
1523                            fidl::encoding::DefaultFuchsiaResourceDialect
1524                        );
1525                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<LookupAdminSetDnsServersRequest>(&header, _body_bytes, handles, &mut req)?;
1526                        let control_handle = LookupAdminControlHandle { inner: this.inner.clone() };
1527                        Ok(LookupAdminRequest::SetDnsServers {
1528                            servers: req.servers,
1529
1530                            responder: LookupAdminSetDnsServersResponder {
1531                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1532                                tx_id: header.tx_id,
1533                            },
1534                        })
1535                    }
1536                    0x614303bf6e72f80f => {
1537                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1538                        let mut req = fidl::new_empty!(
1539                            fidl::encoding::EmptyPayload,
1540                            fidl::encoding::DefaultFuchsiaResourceDialect
1541                        );
1542                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1543                        let control_handle = LookupAdminControlHandle { inner: this.inner.clone() };
1544                        Ok(LookupAdminRequest::GetDnsServers {
1545                            responder: LookupAdminGetDnsServersResponder {
1546                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1547                                tx_id: header.tx_id,
1548                            },
1549                        })
1550                    }
1551                    _ => Err(fidl::Error::UnknownOrdinal {
1552                        ordinal: header.ordinal,
1553                        protocol_name:
1554                            <LookupAdminMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1555                    }),
1556                }))
1557            },
1558        )
1559    }
1560}
1561
1562/// Provides administration controls over name resolution settings.
1563#[derive(Debug)]
1564pub enum LookupAdminRequest {
1565    /// Sets the DNS servers to `servers`
1566    ///
1567    /// + request `servers` The list of servers to use for domain name resolution, in priority
1568    /// order. An empty list means no servers will be used and name resolution may fail. Each
1569    /// `SocketAddress` in `servers` must be a valid unicast socket address. The list of servers
1570    /// will be deduplicated.
1571    /// * error Returns `ZX_ERR_INVALID_ARGS` if any of the provided addresses does not meet the
1572    /// conditions above.
1573    SetDnsServers {
1574        servers: Vec<fidl_fuchsia_net::SocketAddress>,
1575        responder: LookupAdminSetDnsServersResponder,
1576    },
1577    /// Gets the DNS servers currently in use to resolve name lookups.
1578    /// - response `servers` The list of servers in use by `LookupAdmin`, in priority order.
1579    GetDnsServers { responder: LookupAdminGetDnsServersResponder },
1580}
1581
1582impl LookupAdminRequest {
1583    #[allow(irrefutable_let_patterns)]
1584    pub fn into_set_dns_servers(
1585        self,
1586    ) -> Option<(Vec<fidl_fuchsia_net::SocketAddress>, LookupAdminSetDnsServersResponder)> {
1587        if let LookupAdminRequest::SetDnsServers { servers, responder } = self {
1588            Some((servers, responder))
1589        } else {
1590            None
1591        }
1592    }
1593
1594    #[allow(irrefutable_let_patterns)]
1595    pub fn into_get_dns_servers(self) -> Option<(LookupAdminGetDnsServersResponder)> {
1596        if let LookupAdminRequest::GetDnsServers { responder } = self {
1597            Some((responder))
1598        } else {
1599            None
1600        }
1601    }
1602
1603    /// Name of the method defined in FIDL
1604    pub fn method_name(&self) -> &'static str {
1605        match *self {
1606            LookupAdminRequest::SetDnsServers { .. } => "set_dns_servers",
1607            LookupAdminRequest::GetDnsServers { .. } => "get_dns_servers",
1608        }
1609    }
1610}
1611
1612#[derive(Debug, Clone)]
1613pub struct LookupAdminControlHandle {
1614    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1615}
1616
1617impl fidl::endpoints::ControlHandle for LookupAdminControlHandle {
1618    fn shutdown(&self) {
1619        self.inner.shutdown()
1620    }
1621
1622    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1623        self.inner.shutdown_with_epitaph(status)
1624    }
1625
1626    fn is_closed(&self) -> bool {
1627        self.inner.channel().is_closed()
1628    }
1629    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1630        self.inner.channel().on_closed()
1631    }
1632
1633    #[cfg(target_os = "fuchsia")]
1634    fn signal_peer(
1635        &self,
1636        clear_mask: zx::Signals,
1637        set_mask: zx::Signals,
1638    ) -> Result<(), zx_status::Status> {
1639        use fidl::Peered;
1640        self.inner.channel().signal_peer(clear_mask, set_mask)
1641    }
1642}
1643
1644impl LookupAdminControlHandle {}
1645
1646#[must_use = "FIDL methods require a response to be sent"]
1647#[derive(Debug)]
1648pub struct LookupAdminSetDnsServersResponder {
1649    control_handle: std::mem::ManuallyDrop<LookupAdminControlHandle>,
1650    tx_id: u32,
1651}
1652
1653/// Set the the channel to be shutdown (see [`LookupAdminControlHandle::shutdown`])
1654/// if the responder is dropped without sending a response, so that the client
1655/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1656impl std::ops::Drop for LookupAdminSetDnsServersResponder {
1657    fn drop(&mut self) {
1658        self.control_handle.shutdown();
1659        // Safety: drops once, never accessed again
1660        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1661    }
1662}
1663
1664impl fidl::endpoints::Responder for LookupAdminSetDnsServersResponder {
1665    type ControlHandle = LookupAdminControlHandle;
1666
1667    fn control_handle(&self) -> &LookupAdminControlHandle {
1668        &self.control_handle
1669    }
1670
1671    fn drop_without_shutdown(mut self) {
1672        // Safety: drops once, never accessed again due to mem::forget
1673        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1674        // Prevent Drop from running (which would shut down the channel)
1675        std::mem::forget(self);
1676    }
1677}
1678
1679impl LookupAdminSetDnsServersResponder {
1680    /// Sends a response to the FIDL transaction.
1681    ///
1682    /// Sets the channel to shutdown if an error occurs.
1683    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1684        let _result = self.send_raw(result);
1685        if _result.is_err() {
1686            self.control_handle.shutdown();
1687        }
1688        self.drop_without_shutdown();
1689        _result
1690    }
1691
1692    /// Similar to "send" but does not shutdown the channel if an error occurs.
1693    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1694        let _result = self.send_raw(result);
1695        self.drop_without_shutdown();
1696        _result
1697    }
1698
1699    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1700        self.control_handle
1701            .inner
1702            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1703                result,
1704                self.tx_id,
1705                0x55e2b9fcc777be96,
1706                fidl::encoding::DynamicFlags::empty(),
1707            )
1708    }
1709}
1710
1711#[must_use = "FIDL methods require a response to be sent"]
1712#[derive(Debug)]
1713pub struct LookupAdminGetDnsServersResponder {
1714    control_handle: std::mem::ManuallyDrop<LookupAdminControlHandle>,
1715    tx_id: u32,
1716}
1717
1718/// Set the the channel to be shutdown (see [`LookupAdminControlHandle::shutdown`])
1719/// if the responder is dropped without sending a response, so that the client
1720/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1721impl std::ops::Drop for LookupAdminGetDnsServersResponder {
1722    fn drop(&mut self) {
1723        self.control_handle.shutdown();
1724        // Safety: drops once, never accessed again
1725        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1726    }
1727}
1728
1729impl fidl::endpoints::Responder for LookupAdminGetDnsServersResponder {
1730    type ControlHandle = LookupAdminControlHandle;
1731
1732    fn control_handle(&self) -> &LookupAdminControlHandle {
1733        &self.control_handle
1734    }
1735
1736    fn drop_without_shutdown(mut self) {
1737        // Safety: drops once, never accessed again due to mem::forget
1738        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1739        // Prevent Drop from running (which would shut down the channel)
1740        std::mem::forget(self);
1741    }
1742}
1743
1744impl LookupAdminGetDnsServersResponder {
1745    /// Sends a response to the FIDL transaction.
1746    ///
1747    /// Sets the channel to shutdown if an error occurs.
1748    pub fn send(self, mut servers: &[fidl_fuchsia_net::SocketAddress]) -> Result<(), fidl::Error> {
1749        let _result = self.send_raw(servers);
1750        if _result.is_err() {
1751            self.control_handle.shutdown();
1752        }
1753        self.drop_without_shutdown();
1754        _result
1755    }
1756
1757    /// Similar to "send" but does not shutdown the channel if an error occurs.
1758    pub fn send_no_shutdown_on_err(
1759        self,
1760        mut servers: &[fidl_fuchsia_net::SocketAddress],
1761    ) -> Result<(), fidl::Error> {
1762        let _result = self.send_raw(servers);
1763        self.drop_without_shutdown();
1764        _result
1765    }
1766
1767    fn send_raw(&self, mut servers: &[fidl_fuchsia_net::SocketAddress]) -> Result<(), fidl::Error> {
1768        self.control_handle.inner.send::<LookupAdminGetDnsServersResponse>(
1769            (servers,),
1770            self.tx_id,
1771            0x614303bf6e72f80f,
1772            fidl::encoding::DynamicFlags::empty(),
1773        )
1774    }
1775}
1776
1777mod internal {
1778    use super::*;
1779}