Skip to main content

fidl_fuchsia_hardware_power_usb/
fidl_fuchsia_hardware_power_usb.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_hardware_power_usb_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct DebugSetConnectedRequest {
16    pub connected: bool,
17    pub wake_lease: Option<fidl::EventPair>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for DebugSetConnectedRequest {}
21
22#[derive(Debug, PartialEq)]
23pub struct UsbSourceWatchRequest {
24    pub interest: Status,
25    pub wake_on: Status,
26    pub lease: Option<fidl::EventPair>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for UsbSourceWatchRequest {}
30
31#[derive(Debug, PartialEq)]
32pub struct UsbSourceWatchResponse {
33    pub status: Status,
34    pub wake_lease: Option<fidl::EventPair>,
35}
36
37impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for UsbSourceWatchResponse {}
38
39#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
40pub struct DebugMarker;
41
42impl fidl::endpoints::ProtocolMarker for DebugMarker {
43    type Proxy = DebugProxy;
44    type RequestStream = DebugRequestStream;
45    #[cfg(target_os = "fuchsia")]
46    type SynchronousProxy = DebugSynchronousProxy;
47
48    const DEBUG_NAME: &'static str = "fuchsia.hardware.power.usb.Debug";
49}
50impl fidl::endpoints::DiscoverableProtocolMarker for DebugMarker {}
51pub type DebugSetConnectedResult = Result<(), fidl_fuchsia_hardware_power_source::Error>;
52
53pub trait DebugProxyInterface: Send + Sync {
54    type SetConnectedResponseFut: std::future::Future<Output = Result<DebugSetConnectedResult, fidl::Error>>
55        + Send;
56    fn r#set_connected(
57        &self,
58        connected: bool,
59        wake_lease: Option<fidl::EventPair>,
60    ) -> Self::SetConnectedResponseFut;
61}
62#[derive(Debug)]
63#[cfg(target_os = "fuchsia")]
64pub struct DebugSynchronousProxy {
65    client: fidl::client::sync::Client,
66}
67
68#[cfg(target_os = "fuchsia")]
69impl fidl::endpoints::SynchronousProxy for DebugSynchronousProxy {
70    type Proxy = DebugProxy;
71    type Protocol = DebugMarker;
72
73    fn from_channel(inner: fidl::Channel) -> Self {
74        Self::new(inner)
75    }
76
77    fn into_channel(self) -> fidl::Channel {
78        self.client.into_channel()
79    }
80
81    fn as_channel(&self) -> &fidl::Channel {
82        self.client.as_channel()
83    }
84}
85
86#[cfg(target_os = "fuchsia")]
87impl DebugSynchronousProxy {
88    pub fn new(channel: fidl::Channel) -> Self {
89        Self { client: fidl::client::sync::Client::new(channel) }
90    }
91
92    pub fn into_channel(self) -> fidl::Channel {
93        self.client.into_channel()
94    }
95
96    /// Waits until an event arrives and returns it. It is safe for other
97    /// threads to make concurrent requests while waiting for an event.
98    pub fn wait_for_event(
99        &self,
100        deadline: zx::MonotonicInstant,
101    ) -> Result<DebugEvent, fidl::Error> {
102        DebugEvent::decode(self.client.wait_for_event::<DebugMarker>(deadline)?)
103    }
104
105    /// Connects or disconnects the physical Type-C CC lines and USB data switch.
106    ///
107    /// When `connected` is `false`, disables autonomous DRP toggling and opens CC1/CC2
108    /// terminations to simulate a physical cable unplug. When `connected` is `true`,
109    /// restores autonomous DRP Rp/Rd toggling and restarts connection detection; if
110    /// `wake_lease` is provided, the driver holds it across CC attach debounce and
111    /// BC1.2 detection so the system does not re-suspend before USB re-enumerates.
112    pub fn r#set_connected(
113        &self,
114        mut connected: bool,
115        mut wake_lease: Option<fidl::EventPair>,
116        ___deadline: zx::MonotonicInstant,
117    ) -> Result<DebugSetConnectedResult, fidl::Error> {
118        let _response = self
119            .client
120            .send_query::<DebugSetConnectedRequest, fidl::encoding::FlexibleResultType<
121                fidl::encoding::EmptyStruct,
122                fidl_fuchsia_hardware_power_source::Error,
123            >, DebugMarker>(
124                (connected, wake_lease),
125                0x17a772be294b4e27,
126                fidl::encoding::DynamicFlags::FLEXIBLE,
127                ___deadline,
128            )?
129            .into_result::<DebugMarker>("set_connected")?;
130        Ok(_response.map(|x| x))
131    }
132}
133
134#[cfg(target_os = "fuchsia")]
135impl From<DebugSynchronousProxy> for zx::NullableHandle {
136    fn from(value: DebugSynchronousProxy) -> Self {
137        value.into_channel().into()
138    }
139}
140
141#[cfg(target_os = "fuchsia")]
142impl From<fidl::Channel> for DebugSynchronousProxy {
143    fn from(value: fidl::Channel) -> Self {
144        Self::new(value)
145    }
146}
147
148#[cfg(target_os = "fuchsia")]
149impl fidl::endpoints::FromClient for DebugSynchronousProxy {
150    type Protocol = DebugMarker;
151
152    fn from_client(value: fidl::endpoints::ClientEnd<DebugMarker>) -> Self {
153        Self::new(value.into_channel())
154    }
155}
156
157#[derive(Debug, Clone)]
158pub struct DebugProxy {
159    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
160}
161
162impl fidl::endpoints::Proxy for DebugProxy {
163    type Protocol = DebugMarker;
164
165    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
166        Self::new(inner)
167    }
168
169    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
170        self.client.into_channel().map_err(|client| Self { client })
171    }
172
173    fn as_channel(&self) -> &::fidl::AsyncChannel {
174        self.client.as_channel()
175    }
176}
177
178impl DebugProxy {
179    /// Create a new Proxy for fuchsia.hardware.power.usb/Debug.
180    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
181        let protocol_name = <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
182        Self { client: fidl::client::Client::new(channel, protocol_name) }
183    }
184
185    /// Get a Stream of events from the remote end of the protocol.
186    ///
187    /// # Panics
188    ///
189    /// Panics if the event stream was already taken.
190    pub fn take_event_stream(&self) -> DebugEventStream {
191        DebugEventStream { event_receiver: self.client.take_event_receiver() }
192    }
193
194    /// Connects or disconnects the physical Type-C CC lines and USB data switch.
195    ///
196    /// When `connected` is `false`, disables autonomous DRP toggling and opens CC1/CC2
197    /// terminations to simulate a physical cable unplug. When `connected` is `true`,
198    /// restores autonomous DRP Rp/Rd toggling and restarts connection detection; if
199    /// `wake_lease` is provided, the driver holds it across CC attach debounce and
200    /// BC1.2 detection so the system does not re-suspend before USB re-enumerates.
201    pub fn r#set_connected(
202        &self,
203        mut connected: bool,
204        mut wake_lease: Option<fidl::EventPair>,
205    ) -> fidl::client::QueryResponseFut<
206        DebugSetConnectedResult,
207        fidl::encoding::DefaultFuchsiaResourceDialect,
208    > {
209        DebugProxyInterface::r#set_connected(self, connected, wake_lease)
210    }
211}
212
213impl DebugProxyInterface for DebugProxy {
214    type SetConnectedResponseFut = fidl::client::QueryResponseFut<
215        DebugSetConnectedResult,
216        fidl::encoding::DefaultFuchsiaResourceDialect,
217    >;
218    fn r#set_connected(
219        &self,
220        mut connected: bool,
221        mut wake_lease: Option<fidl::EventPair>,
222    ) -> Self::SetConnectedResponseFut {
223        fn _decode(
224            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
225        ) -> Result<DebugSetConnectedResult, fidl::Error> {
226            let _response = fidl::client::decode_transaction_body::<
227                fidl::encoding::FlexibleResultType<
228                    fidl::encoding::EmptyStruct,
229                    fidl_fuchsia_hardware_power_source::Error,
230                >,
231                fidl::encoding::DefaultFuchsiaResourceDialect,
232                0x17a772be294b4e27,
233            >(_buf?)?
234            .into_result::<DebugMarker>("set_connected")?;
235            Ok(_response.map(|x| x))
236        }
237        self.client.send_query_and_decode::<DebugSetConnectedRequest, DebugSetConnectedResult>(
238            (connected, wake_lease),
239            0x17a772be294b4e27,
240            fidl::encoding::DynamicFlags::FLEXIBLE,
241            _decode,
242        )
243    }
244}
245
246pub struct DebugEventStream {
247    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
248}
249
250impl std::marker::Unpin for DebugEventStream {}
251
252impl futures::stream::FusedStream for DebugEventStream {
253    fn is_terminated(&self) -> bool {
254        self.event_receiver.is_terminated()
255    }
256}
257
258impl futures::Stream for DebugEventStream {
259    type Item = Result<DebugEvent, fidl::Error>;
260
261    fn poll_next(
262        mut self: std::pin::Pin<&mut Self>,
263        cx: &mut std::task::Context<'_>,
264    ) -> std::task::Poll<Option<Self::Item>> {
265        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
266            &mut self.event_receiver,
267            cx
268        )?) {
269            Some(buf) => std::task::Poll::Ready(Some(DebugEvent::decode(buf))),
270            None => std::task::Poll::Ready(None),
271        }
272    }
273}
274
275#[derive(Debug)]
276pub enum DebugEvent {
277    #[non_exhaustive]
278    _UnknownEvent {
279        /// Ordinal of the event that was sent.
280        ordinal: u64,
281    },
282}
283
284impl DebugEvent {
285    /// Decodes a message buffer as a [`DebugEvent`].
286    fn decode(
287        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
288    ) -> Result<DebugEvent, fidl::Error> {
289        let (bytes, _handles) = buf.split_mut();
290        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
291        debug_assert_eq!(tx_header.tx_id, 0);
292        match tx_header.ordinal {
293            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
294                Ok(DebugEvent::_UnknownEvent { ordinal: tx_header.ordinal })
295            }
296            _ => Err(fidl::Error::UnknownOrdinal {
297                ordinal: tx_header.ordinal,
298                protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
299            }),
300        }
301    }
302}
303
304/// A Stream of incoming requests for fuchsia.hardware.power.usb/Debug.
305pub struct DebugRequestStream {
306    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
307    is_terminated: bool,
308}
309
310impl std::marker::Unpin for DebugRequestStream {}
311
312impl futures::stream::FusedStream for DebugRequestStream {
313    fn is_terminated(&self) -> bool {
314        self.is_terminated
315    }
316}
317
318impl fidl::endpoints::RequestStream for DebugRequestStream {
319    type Protocol = DebugMarker;
320    type ControlHandle = DebugControlHandle;
321
322    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
323        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
324    }
325
326    fn control_handle(&self) -> Self::ControlHandle {
327        DebugControlHandle { inner: self.inner.clone() }
328    }
329
330    fn into_inner(
331        self,
332    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
333    {
334        (self.inner, self.is_terminated)
335    }
336
337    fn from_inner(
338        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
339        is_terminated: bool,
340    ) -> Self {
341        Self { inner, is_terminated }
342    }
343}
344
345impl futures::Stream for DebugRequestStream {
346    type Item = Result<DebugRequest, fidl::Error>;
347
348    fn poll_next(
349        mut self: std::pin::Pin<&mut Self>,
350        cx: &mut std::task::Context<'_>,
351    ) -> std::task::Poll<Option<Self::Item>> {
352        let this = &mut *self;
353        if this.inner.check_shutdown(cx) {
354            this.is_terminated = true;
355            return std::task::Poll::Ready(None);
356        }
357        if this.is_terminated {
358            panic!("polled DebugRequestStream after completion");
359        }
360        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
361            |bytes, handles| {
362                match this.inner.channel().read_etc(cx, bytes, handles) {
363                    std::task::Poll::Ready(Ok(())) => {}
364                    std::task::Poll::Pending => return std::task::Poll::Pending,
365                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
366                        this.is_terminated = true;
367                        return std::task::Poll::Ready(None);
368                    }
369                    std::task::Poll::Ready(Err(e)) => {
370                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
371                            e.into(),
372                        ))));
373                    }
374                }
375
376                // A message has been received from the channel
377                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
378
379                std::task::Poll::Ready(Some(match header.ordinal {
380                    0x17a772be294b4e27 => {
381                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
382                        let mut req = fidl::new_empty!(
383                            DebugSetConnectedRequest,
384                            fidl::encoding::DefaultFuchsiaResourceDialect
385                        );
386                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DebugSetConnectedRequest>(&header, _body_bytes, handles, &mut req)?;
387                        let control_handle = DebugControlHandle { inner: this.inner.clone() };
388                        Ok(DebugRequest::SetConnected {
389                            connected: req.connected,
390                            wake_lease: req.wake_lease,
391
392                            responder: DebugSetConnectedResponder {
393                                control_handle: std::mem::ManuallyDrop::new(control_handle),
394                                tx_id: header.tx_id,
395                            },
396                        })
397                    }
398                    _ if header.tx_id == 0
399                        && header
400                            .dynamic_flags()
401                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
402                    {
403                        Ok(DebugRequest::_UnknownMethod {
404                            ordinal: header.ordinal,
405                            control_handle: DebugControlHandle { inner: this.inner.clone() },
406                            method_type: fidl::MethodType::OneWay,
407                        })
408                    }
409                    _ if header
410                        .dynamic_flags()
411                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
412                    {
413                        this.inner.send_framework_err(
414                            fidl::encoding::FrameworkErr::UnknownMethod,
415                            header.tx_id,
416                            header.ordinal,
417                            header.dynamic_flags(),
418                            (bytes, handles),
419                        )?;
420                        Ok(DebugRequest::_UnknownMethod {
421                            ordinal: header.ordinal,
422                            control_handle: DebugControlHandle { inner: this.inner.clone() },
423                            method_type: fidl::MethodType::TwoWay,
424                        })
425                    }
426                    _ => Err(fidl::Error::UnknownOrdinal {
427                        ordinal: header.ordinal,
428                        protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
429                    }),
430                }))
431            },
432        )
433    }
434}
435
436/// Protocol for test and debug control of the USB Type-C port (e.g. cable-breaker).
437#[derive(Debug)]
438pub enum DebugRequest {
439    /// Connects or disconnects the physical Type-C CC lines and USB data switch.
440    ///
441    /// When `connected` is `false`, disables autonomous DRP toggling and opens CC1/CC2
442    /// terminations to simulate a physical cable unplug. When `connected` is `true`,
443    /// restores autonomous DRP Rp/Rd toggling and restarts connection detection; if
444    /// `wake_lease` is provided, the driver holds it across CC attach debounce and
445    /// BC1.2 detection so the system does not re-suspend before USB re-enumerates.
446    SetConnected {
447        connected: bool,
448        wake_lease: Option<fidl::EventPair>,
449        responder: DebugSetConnectedResponder,
450    },
451    /// An interaction was received which does not match any known method.
452    #[non_exhaustive]
453    _UnknownMethod {
454        /// Ordinal of the method that was called.
455        ordinal: u64,
456        control_handle: DebugControlHandle,
457        method_type: fidl::MethodType,
458    },
459}
460
461impl DebugRequest {
462    #[allow(irrefutable_let_patterns)]
463    pub fn into_set_connected(
464        self,
465    ) -> Option<(bool, Option<fidl::EventPair>, DebugSetConnectedResponder)> {
466        if let DebugRequest::SetConnected { connected, wake_lease, responder } = self {
467            Some((connected, wake_lease, responder))
468        } else {
469            None
470        }
471    }
472
473    /// Name of the method defined in FIDL
474    pub fn method_name(&self) -> &'static str {
475        match *self {
476            DebugRequest::SetConnected { .. } => "set_connected",
477            DebugRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
478                "unknown one-way method"
479            }
480            DebugRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
481                "unknown two-way method"
482            }
483        }
484    }
485}
486
487#[derive(Debug, Clone)]
488pub struct DebugControlHandle {
489    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
490}
491
492impl DebugControlHandle {
493    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
494        self.inner.shutdown_with_epitaph(status.into())
495    }
496}
497
498impl fidl::endpoints::ControlHandle for DebugControlHandle {
499    fn shutdown(&self) {
500        self.inner.shutdown()
501    }
502
503    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
504        self.inner.shutdown_with_epitaph(status)
505    }
506
507    fn is_closed(&self) -> bool {
508        self.inner.channel().is_closed()
509    }
510    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
511        self.inner.channel().on_closed()
512    }
513
514    #[cfg(target_os = "fuchsia")]
515    fn signal_peer(
516        &self,
517        clear_mask: zx::Signals,
518        set_mask: zx::Signals,
519    ) -> Result<(), zx_status::Status> {
520        use fidl::Peered;
521        self.inner.channel().signal_peer(clear_mask, set_mask)
522    }
523}
524
525impl DebugControlHandle {}
526
527#[must_use = "FIDL methods require a response to be sent"]
528#[derive(Debug)]
529pub struct DebugSetConnectedResponder {
530    control_handle: std::mem::ManuallyDrop<DebugControlHandle>,
531    tx_id: u32,
532}
533
534/// Set the the channel to be shutdown (see [`DebugControlHandle::shutdown`])
535/// if the responder is dropped without sending a response, so that the client
536/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
537impl std::ops::Drop for DebugSetConnectedResponder {
538    fn drop(&mut self) {
539        self.control_handle.shutdown();
540        // Safety: drops once, never accessed again
541        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
542    }
543}
544
545impl fidl::endpoints::Responder for DebugSetConnectedResponder {
546    type ControlHandle = DebugControlHandle;
547
548    fn control_handle(&self) -> &DebugControlHandle {
549        &self.control_handle
550    }
551
552    fn drop_without_shutdown(mut self) {
553        // Safety: drops once, never accessed again due to mem::forget
554        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
555        // Prevent Drop from running (which would shut down the channel)
556        std::mem::forget(self);
557    }
558}
559
560impl DebugSetConnectedResponder {
561    /// Sends a response to the FIDL transaction.
562    ///
563    /// Sets the channel to shutdown if an error occurs.
564    pub fn send(
565        self,
566        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
567    ) -> Result<(), fidl::Error> {
568        let _result = self.send_raw(result);
569        if _result.is_err() {
570            self.control_handle.shutdown();
571        }
572        self.drop_without_shutdown();
573        _result
574    }
575
576    /// Similar to "send" but does not shutdown the channel if an error occurs.
577    pub fn send_no_shutdown_on_err(
578        self,
579        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
580    ) -> Result<(), fidl::Error> {
581        let _result = self.send_raw(result);
582        self.drop_without_shutdown();
583        _result
584    }
585
586    fn send_raw(
587        &self,
588        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
589    ) -> Result<(), fidl::Error> {
590        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
591            fidl::encoding::EmptyStruct,
592            fidl_fuchsia_hardware_power_source::Error,
593        >>(
594            fidl::encoding::FlexibleResult::new(result),
595            self.tx_id,
596            0x17a772be294b4e27,
597            fidl::encoding::DynamicFlags::FLEXIBLE,
598        )
599    }
600}
601
602#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
603pub struct UsbSourceMarker;
604
605impl fidl::endpoints::ProtocolMarker for UsbSourceMarker {
606    type Proxy = UsbSourceProxy;
607    type RequestStream = UsbSourceRequestStream;
608    #[cfg(target_os = "fuchsia")]
609    type SynchronousProxy = UsbSourceSynchronousProxy;
610
611    const DEBUG_NAME: &'static str = "(anonymous) UsbSource";
612}
613pub type UsbSourceGetSpecResult = Result<Spec, fidl_fuchsia_hardware_power_source::Error>;
614pub type UsbSourceGetStatusResult = Result<Status, fidl_fuchsia_hardware_power_source::Error>;
615pub type UsbSourceSetInputCurrentLimitResult =
616    Result<(), fidl_fuchsia_hardware_power_source::Error>;
617pub type UsbSourceWatchResult =
618    Result<(Status, Option<fidl::EventPair>), fidl_fuchsia_hardware_power_source::Error>;
619
620pub trait UsbSourceProxyInterface: Send + Sync {
621    type GetSpecResponseFut: std::future::Future<Output = Result<UsbSourceGetSpecResult, fidl::Error>>
622        + Send;
623    fn r#get_spec(&self) -> Self::GetSpecResponseFut;
624    type GetStatusResponseFut: std::future::Future<Output = Result<UsbSourceGetStatusResult, fidl::Error>>
625        + Send;
626    fn r#get_status(&self) -> Self::GetStatusResponseFut;
627    type SetInputCurrentLimitResponseFut: std::future::Future<Output = Result<UsbSourceSetInputCurrentLimitResult, fidl::Error>>
628        + Send;
629    fn r#set_input_current_limit(&self, limit_ua: u32) -> Self::SetInputCurrentLimitResponseFut;
630    type WatchResponseFut: std::future::Future<Output = Result<UsbSourceWatchResult, fidl::Error>>
631        + Send;
632    fn r#watch(
633        &self,
634        interest: &Status,
635        wake_on: &Status,
636        lease: Option<fidl::EventPair>,
637    ) -> Self::WatchResponseFut;
638}
639#[derive(Debug)]
640#[cfg(target_os = "fuchsia")]
641pub struct UsbSourceSynchronousProxy {
642    client: fidl::client::sync::Client,
643}
644
645#[cfg(target_os = "fuchsia")]
646impl fidl::endpoints::SynchronousProxy for UsbSourceSynchronousProxy {
647    type Proxy = UsbSourceProxy;
648    type Protocol = UsbSourceMarker;
649
650    fn from_channel(inner: fidl::Channel) -> Self {
651        Self::new(inner)
652    }
653
654    fn into_channel(self) -> fidl::Channel {
655        self.client.into_channel()
656    }
657
658    fn as_channel(&self) -> &fidl::Channel {
659        self.client.as_channel()
660    }
661}
662
663#[cfg(target_os = "fuchsia")]
664impl UsbSourceSynchronousProxy {
665    pub fn new(channel: fidl::Channel) -> Self {
666        Self { client: fidl::client::sync::Client::new(channel) }
667    }
668
669    pub fn into_channel(self) -> fidl::Channel {
670        self.client.into_channel()
671    }
672
673    /// Waits until an event arrives and returns it. It is safe for other
674    /// threads to make concurrent requests while waiting for an event.
675    pub fn wait_for_event(
676        &self,
677        deadline: zx::MonotonicInstant,
678    ) -> Result<UsbSourceEvent, fidl::Error> {
679        UsbSourceEvent::decode(self.client.wait_for_event::<UsbSourceMarker>(deadline)?)
680    }
681
682    /// Returns static hardware characteristics of the USB source immediately.
683    pub fn r#get_spec(
684        &self,
685        ___deadline: zx::MonotonicInstant,
686    ) -> Result<UsbSourceGetSpecResult, fidl::Error> {
687        let _response = self
688            .client
689            .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::FlexibleResultType<
690                UsbSourceGetSpecResponse,
691                fidl_fuchsia_hardware_power_source::Error,
692            >, UsbSourceMarker>(
693                (),
694                0xa6da1fd32ae9e5e,
695                fidl::encoding::DynamicFlags::FLEXIBLE,
696                ___deadline,
697            )?
698            .into_result::<UsbSourceMarker>("get_spec")?;
699        Ok(_response.map(|x| x.spec))
700    }
701
702    /// Returns dynamic status of the USB source immediately.
703    pub fn r#get_status(
704        &self,
705        ___deadline: zx::MonotonicInstant,
706    ) -> Result<UsbSourceGetStatusResult, fidl::Error> {
707        let _response = self
708            .client
709            .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::FlexibleResultType<
710                UsbSourceGetStatusResponse,
711                fidl_fuchsia_hardware_power_source::Error,
712            >, UsbSourceMarker>(
713                (),
714                0x48d44a3f9b92471a,
715                fidl::encoding::DynamicFlags::FLEXIBLE,
716                ___deadline,
717            )?
718            .into_result::<UsbSourceMarker>("get_status")?;
719        Ok(_response.map(|x| x.status))
720    }
721
722    /// Set the maximum current limit for this USB input.
723    pub fn r#set_input_current_limit(
724        &self,
725        mut limit_ua: u32,
726        ___deadline: zx::MonotonicInstant,
727    ) -> Result<UsbSourceSetInputCurrentLimitResult, fidl::Error> {
728        let _response = self
729            .client
730            .send_query::<UsbSourceSetInputCurrentLimitRequest, fidl::encoding::FlexibleResultType<
731                fidl::encoding::EmptyStruct,
732                fidl_fuchsia_hardware_power_source::Error,
733            >, UsbSourceMarker>(
734                (limit_ua,),
735                0x7633140057298018,
736                fidl::encoding::DynamicFlags::FLEXIBLE,
737                ___deadline,
738            )?
739            .into_result::<UsbSourceMarker>("set_input_current_limit")?;
740        Ok(_response.map(|x| x))
741    }
742
743    /// Hanging get for status updates.
744    /// See [`fuchsia.hardware.power.source/Source.Watch`] for semantics.
745    ///
746    /// # Errors
747    ///
748    /// * `ALREADY_BOUND` if `Watch` is called before the previous call completes.
749    pub fn r#watch(
750        &self,
751        mut interest: &Status,
752        mut wake_on: &Status,
753        mut lease: Option<fidl::EventPair>,
754        ___deadline: zx::MonotonicInstant,
755    ) -> Result<UsbSourceWatchResult, fidl::Error> {
756        let _response = self
757            .client
758            .send_query::<UsbSourceWatchRequest, fidl::encoding::FlexibleResultType<
759                UsbSourceWatchResponse,
760                fidl_fuchsia_hardware_power_source::Error,
761            >, UsbSourceMarker>(
762                (interest, wake_on, lease),
763                0x740e01eea4327def,
764                fidl::encoding::DynamicFlags::FLEXIBLE,
765                ___deadline,
766            )?
767            .into_result::<UsbSourceMarker>("watch")?;
768        Ok(_response.map(|x| (x.status, x.wake_lease)))
769    }
770}
771
772#[cfg(target_os = "fuchsia")]
773impl From<UsbSourceSynchronousProxy> for zx::NullableHandle {
774    fn from(value: UsbSourceSynchronousProxy) -> Self {
775        value.into_channel().into()
776    }
777}
778
779#[cfg(target_os = "fuchsia")]
780impl From<fidl::Channel> for UsbSourceSynchronousProxy {
781    fn from(value: fidl::Channel) -> Self {
782        Self::new(value)
783    }
784}
785
786#[cfg(target_os = "fuchsia")]
787impl fidl::endpoints::FromClient for UsbSourceSynchronousProxy {
788    type Protocol = UsbSourceMarker;
789
790    fn from_client(value: fidl::endpoints::ClientEnd<UsbSourceMarker>) -> Self {
791        Self::new(value.into_channel())
792    }
793}
794
795#[derive(Debug, Clone)]
796pub struct UsbSourceProxy {
797    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
798}
799
800impl fidl::endpoints::Proxy for UsbSourceProxy {
801    type Protocol = UsbSourceMarker;
802
803    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
804        Self::new(inner)
805    }
806
807    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
808        self.client.into_channel().map_err(|client| Self { client })
809    }
810
811    fn as_channel(&self) -> &::fidl::AsyncChannel {
812        self.client.as_channel()
813    }
814}
815
816impl UsbSourceProxy {
817    /// Create a new Proxy for fuchsia.hardware.power.usb/UsbSource.
818    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
819        let protocol_name = <UsbSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
820        Self { client: fidl::client::Client::new(channel, protocol_name) }
821    }
822
823    /// Get a Stream of events from the remote end of the protocol.
824    ///
825    /// # Panics
826    ///
827    /// Panics if the event stream was already taken.
828    pub fn take_event_stream(&self) -> UsbSourceEventStream {
829        UsbSourceEventStream { event_receiver: self.client.take_event_receiver() }
830    }
831
832    /// Returns static hardware characteristics of the USB source immediately.
833    pub fn r#get_spec(
834        &self,
835    ) -> fidl::client::QueryResponseFut<
836        UsbSourceGetSpecResult,
837        fidl::encoding::DefaultFuchsiaResourceDialect,
838    > {
839        UsbSourceProxyInterface::r#get_spec(self)
840    }
841
842    /// Returns dynamic status of the USB source immediately.
843    pub fn r#get_status(
844        &self,
845    ) -> fidl::client::QueryResponseFut<
846        UsbSourceGetStatusResult,
847        fidl::encoding::DefaultFuchsiaResourceDialect,
848    > {
849        UsbSourceProxyInterface::r#get_status(self)
850    }
851
852    /// Set the maximum current limit for this USB input.
853    pub fn r#set_input_current_limit(
854        &self,
855        mut limit_ua: u32,
856    ) -> fidl::client::QueryResponseFut<
857        UsbSourceSetInputCurrentLimitResult,
858        fidl::encoding::DefaultFuchsiaResourceDialect,
859    > {
860        UsbSourceProxyInterface::r#set_input_current_limit(self, limit_ua)
861    }
862
863    /// Hanging get for status updates.
864    /// See [`fuchsia.hardware.power.source/Source.Watch`] for semantics.
865    ///
866    /// # Errors
867    ///
868    /// * `ALREADY_BOUND` if `Watch` is called before the previous call completes.
869    pub fn r#watch(
870        &self,
871        mut interest: &Status,
872        mut wake_on: &Status,
873        mut lease: Option<fidl::EventPair>,
874    ) -> fidl::client::QueryResponseFut<
875        UsbSourceWatchResult,
876        fidl::encoding::DefaultFuchsiaResourceDialect,
877    > {
878        UsbSourceProxyInterface::r#watch(self, interest, wake_on, lease)
879    }
880}
881
882impl UsbSourceProxyInterface for UsbSourceProxy {
883    type GetSpecResponseFut = fidl::client::QueryResponseFut<
884        UsbSourceGetSpecResult,
885        fidl::encoding::DefaultFuchsiaResourceDialect,
886    >;
887    fn r#get_spec(&self) -> Self::GetSpecResponseFut {
888        fn _decode(
889            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
890        ) -> Result<UsbSourceGetSpecResult, fidl::Error> {
891            let _response = fidl::client::decode_transaction_body::<
892                fidl::encoding::FlexibleResultType<
893                    UsbSourceGetSpecResponse,
894                    fidl_fuchsia_hardware_power_source::Error,
895                >,
896                fidl::encoding::DefaultFuchsiaResourceDialect,
897                0xa6da1fd32ae9e5e,
898            >(_buf?)?
899            .into_result::<UsbSourceMarker>("get_spec")?;
900            Ok(_response.map(|x| x.spec))
901        }
902        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, UsbSourceGetSpecResult>(
903            (),
904            0xa6da1fd32ae9e5e,
905            fidl::encoding::DynamicFlags::FLEXIBLE,
906            _decode,
907        )
908    }
909
910    type GetStatusResponseFut = fidl::client::QueryResponseFut<
911        UsbSourceGetStatusResult,
912        fidl::encoding::DefaultFuchsiaResourceDialect,
913    >;
914    fn r#get_status(&self) -> Self::GetStatusResponseFut {
915        fn _decode(
916            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
917        ) -> Result<UsbSourceGetStatusResult, fidl::Error> {
918            let _response = fidl::client::decode_transaction_body::<
919                fidl::encoding::FlexibleResultType<
920                    UsbSourceGetStatusResponse,
921                    fidl_fuchsia_hardware_power_source::Error,
922                >,
923                fidl::encoding::DefaultFuchsiaResourceDialect,
924                0x48d44a3f9b92471a,
925            >(_buf?)?
926            .into_result::<UsbSourceMarker>("get_status")?;
927            Ok(_response.map(|x| x.status))
928        }
929        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, UsbSourceGetStatusResult>(
930            (),
931            0x48d44a3f9b92471a,
932            fidl::encoding::DynamicFlags::FLEXIBLE,
933            _decode,
934        )
935    }
936
937    type SetInputCurrentLimitResponseFut = fidl::client::QueryResponseFut<
938        UsbSourceSetInputCurrentLimitResult,
939        fidl::encoding::DefaultFuchsiaResourceDialect,
940    >;
941    fn r#set_input_current_limit(
942        &self,
943        mut limit_ua: u32,
944    ) -> Self::SetInputCurrentLimitResponseFut {
945        fn _decode(
946            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
947        ) -> Result<UsbSourceSetInputCurrentLimitResult, fidl::Error> {
948            let _response = fidl::client::decode_transaction_body::<
949                fidl::encoding::FlexibleResultType<
950                    fidl::encoding::EmptyStruct,
951                    fidl_fuchsia_hardware_power_source::Error,
952                >,
953                fidl::encoding::DefaultFuchsiaResourceDialect,
954                0x7633140057298018,
955            >(_buf?)?
956            .into_result::<UsbSourceMarker>("set_input_current_limit")?;
957            Ok(_response.map(|x| x))
958        }
959        self.client.send_query_and_decode::<
960            UsbSourceSetInputCurrentLimitRequest,
961            UsbSourceSetInputCurrentLimitResult,
962        >(
963            (limit_ua,),
964            0x7633140057298018,
965            fidl::encoding::DynamicFlags::FLEXIBLE,
966            _decode,
967        )
968    }
969
970    type WatchResponseFut = fidl::client::QueryResponseFut<
971        UsbSourceWatchResult,
972        fidl::encoding::DefaultFuchsiaResourceDialect,
973    >;
974    fn r#watch(
975        &self,
976        mut interest: &Status,
977        mut wake_on: &Status,
978        mut lease: Option<fidl::EventPair>,
979    ) -> Self::WatchResponseFut {
980        fn _decode(
981            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
982        ) -> Result<UsbSourceWatchResult, fidl::Error> {
983            let _response = fidl::client::decode_transaction_body::<
984                fidl::encoding::FlexibleResultType<
985                    UsbSourceWatchResponse,
986                    fidl_fuchsia_hardware_power_source::Error,
987                >,
988                fidl::encoding::DefaultFuchsiaResourceDialect,
989                0x740e01eea4327def,
990            >(_buf?)?
991            .into_result::<UsbSourceMarker>("watch")?;
992            Ok(_response.map(|x| (x.status, x.wake_lease)))
993        }
994        self.client.send_query_and_decode::<UsbSourceWatchRequest, UsbSourceWatchResult>(
995            (interest, wake_on, lease),
996            0x740e01eea4327def,
997            fidl::encoding::DynamicFlags::FLEXIBLE,
998            _decode,
999        )
1000    }
1001}
1002
1003pub struct UsbSourceEventStream {
1004    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1005}
1006
1007impl std::marker::Unpin for UsbSourceEventStream {}
1008
1009impl futures::stream::FusedStream for UsbSourceEventStream {
1010    fn is_terminated(&self) -> bool {
1011        self.event_receiver.is_terminated()
1012    }
1013}
1014
1015impl futures::Stream for UsbSourceEventStream {
1016    type Item = Result<UsbSourceEvent, fidl::Error>;
1017
1018    fn poll_next(
1019        mut self: std::pin::Pin<&mut Self>,
1020        cx: &mut std::task::Context<'_>,
1021    ) -> std::task::Poll<Option<Self::Item>> {
1022        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1023            &mut self.event_receiver,
1024            cx
1025        )?) {
1026            Some(buf) => std::task::Poll::Ready(Some(UsbSourceEvent::decode(buf))),
1027            None => std::task::Poll::Ready(None),
1028        }
1029    }
1030}
1031
1032#[derive(Debug)]
1033pub enum UsbSourceEvent {
1034    #[non_exhaustive]
1035    _UnknownEvent {
1036        /// Ordinal of the event that was sent.
1037        ordinal: u64,
1038    },
1039}
1040
1041impl UsbSourceEvent {
1042    /// Decodes a message buffer as a [`UsbSourceEvent`].
1043    fn decode(
1044        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1045    ) -> Result<UsbSourceEvent, fidl::Error> {
1046        let (bytes, _handles) = buf.split_mut();
1047        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1048        debug_assert_eq!(tx_header.tx_id, 0);
1049        match tx_header.ordinal {
1050            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1051                Ok(UsbSourceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
1052            }
1053            _ => Err(fidl::Error::UnknownOrdinal {
1054                ordinal: tx_header.ordinal,
1055                protocol_name: <UsbSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1056            }),
1057        }
1058    }
1059}
1060
1061/// A Stream of incoming requests for fuchsia.hardware.power.usb/UsbSource.
1062pub struct UsbSourceRequestStream {
1063    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1064    is_terminated: bool,
1065}
1066
1067impl std::marker::Unpin for UsbSourceRequestStream {}
1068
1069impl futures::stream::FusedStream for UsbSourceRequestStream {
1070    fn is_terminated(&self) -> bool {
1071        self.is_terminated
1072    }
1073}
1074
1075impl fidl::endpoints::RequestStream for UsbSourceRequestStream {
1076    type Protocol = UsbSourceMarker;
1077    type ControlHandle = UsbSourceControlHandle;
1078
1079    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1080        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1081    }
1082
1083    fn control_handle(&self) -> Self::ControlHandle {
1084        UsbSourceControlHandle { inner: self.inner.clone() }
1085    }
1086
1087    fn into_inner(
1088        self,
1089    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1090    {
1091        (self.inner, self.is_terminated)
1092    }
1093
1094    fn from_inner(
1095        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1096        is_terminated: bool,
1097    ) -> Self {
1098        Self { inner, is_terminated }
1099    }
1100}
1101
1102impl futures::Stream for UsbSourceRequestStream {
1103    type Item = Result<UsbSourceRequest, fidl::Error>;
1104
1105    fn poll_next(
1106        mut self: std::pin::Pin<&mut Self>,
1107        cx: &mut std::task::Context<'_>,
1108    ) -> std::task::Poll<Option<Self::Item>> {
1109        let this = &mut *self;
1110        if this.inner.check_shutdown(cx) {
1111            this.is_terminated = true;
1112            return std::task::Poll::Ready(None);
1113        }
1114        if this.is_terminated {
1115            panic!("polled UsbSourceRequestStream after completion");
1116        }
1117        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1118            |bytes, handles| {
1119                match this.inner.channel().read_etc(cx, bytes, handles) {
1120                    std::task::Poll::Ready(Ok(())) => {}
1121                    std::task::Poll::Pending => return std::task::Poll::Pending,
1122                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1123                        this.is_terminated = true;
1124                        return std::task::Poll::Ready(None);
1125                    }
1126                    std::task::Poll::Ready(Err(e)) => {
1127                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1128                            e.into(),
1129                        ))));
1130                    }
1131                }
1132
1133                // A message has been received from the channel
1134                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1135
1136                std::task::Poll::Ready(Some(match header.ordinal {
1137                    0xa6da1fd32ae9e5e => {
1138                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1139                        let mut req = fidl::new_empty!(
1140                            fidl::encoding::EmptyPayload,
1141                            fidl::encoding::DefaultFuchsiaResourceDialect
1142                        );
1143                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1144                        let control_handle = UsbSourceControlHandle { inner: this.inner.clone() };
1145                        Ok(UsbSourceRequest::GetSpec {
1146                            responder: UsbSourceGetSpecResponder {
1147                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1148                                tx_id: header.tx_id,
1149                            },
1150                        })
1151                    }
1152                    0x48d44a3f9b92471a => {
1153                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1154                        let mut req = fidl::new_empty!(
1155                            fidl::encoding::EmptyPayload,
1156                            fidl::encoding::DefaultFuchsiaResourceDialect
1157                        );
1158                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1159                        let control_handle = UsbSourceControlHandle { inner: this.inner.clone() };
1160                        Ok(UsbSourceRequest::GetStatus {
1161                            responder: UsbSourceGetStatusResponder {
1162                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1163                                tx_id: header.tx_id,
1164                            },
1165                        })
1166                    }
1167                    0x7633140057298018 => {
1168                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1169                        let mut req = fidl::new_empty!(
1170                            UsbSourceSetInputCurrentLimitRequest,
1171                            fidl::encoding::DefaultFuchsiaResourceDialect
1172                        );
1173                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbSourceSetInputCurrentLimitRequest>(&header, _body_bytes, handles, &mut req)?;
1174                        let control_handle = UsbSourceControlHandle { inner: this.inner.clone() };
1175                        Ok(UsbSourceRequest::SetInputCurrentLimit {
1176                            limit_ua: req.limit_ua,
1177
1178                            responder: UsbSourceSetInputCurrentLimitResponder {
1179                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1180                                tx_id: header.tx_id,
1181                            },
1182                        })
1183                    }
1184                    0x740e01eea4327def => {
1185                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1186                        let mut req = fidl::new_empty!(
1187                            UsbSourceWatchRequest,
1188                            fidl::encoding::DefaultFuchsiaResourceDialect
1189                        );
1190                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbSourceWatchRequest>(&header, _body_bytes, handles, &mut req)?;
1191                        let control_handle = UsbSourceControlHandle { inner: this.inner.clone() };
1192                        Ok(UsbSourceRequest::Watch {
1193                            interest: req.interest,
1194                            wake_on: req.wake_on,
1195                            lease: req.lease,
1196
1197                            responder: UsbSourceWatchResponder {
1198                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1199                                tx_id: header.tx_id,
1200                            },
1201                        })
1202                    }
1203                    _ if header.tx_id == 0
1204                        && header
1205                            .dynamic_flags()
1206                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1207                    {
1208                        Ok(UsbSourceRequest::_UnknownMethod {
1209                            ordinal: header.ordinal,
1210                            control_handle: UsbSourceControlHandle { inner: this.inner.clone() },
1211                            method_type: fidl::MethodType::OneWay,
1212                        })
1213                    }
1214                    _ if header
1215                        .dynamic_flags()
1216                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1217                    {
1218                        this.inner.send_framework_err(
1219                            fidl::encoding::FrameworkErr::UnknownMethod,
1220                            header.tx_id,
1221                            header.ordinal,
1222                            header.dynamic_flags(),
1223                            (bytes, handles),
1224                        )?;
1225                        Ok(UsbSourceRequest::_UnknownMethod {
1226                            ordinal: header.ordinal,
1227                            control_handle: UsbSourceControlHandle { inner: this.inner.clone() },
1228                            method_type: fidl::MethodType::TwoWay,
1229                        })
1230                    }
1231                    _ => Err(fidl::Error::UnknownOrdinal {
1232                        ordinal: header.ordinal,
1233                        protocol_name:
1234                            <UsbSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1235                    }),
1236                }))
1237            },
1238        )
1239    }
1240}
1241
1242#[derive(Debug)]
1243pub enum UsbSourceRequest {
1244    /// Returns static hardware characteristics of the USB source immediately.
1245    GetSpec { responder: UsbSourceGetSpecResponder },
1246    /// Returns dynamic status of the USB source immediately.
1247    GetStatus { responder: UsbSourceGetStatusResponder },
1248    /// Set the maximum current limit for this USB input.
1249    SetInputCurrentLimit { limit_ua: u32, responder: UsbSourceSetInputCurrentLimitResponder },
1250    /// Hanging get for status updates.
1251    /// See [`fuchsia.hardware.power.source/Source.Watch`] for semantics.
1252    ///
1253    /// # Errors
1254    ///
1255    /// * `ALREADY_BOUND` if `Watch` is called before the previous call completes.
1256    Watch {
1257        interest: Status,
1258        wake_on: Status,
1259        lease: Option<fidl::EventPair>,
1260        responder: UsbSourceWatchResponder,
1261    },
1262    /// An interaction was received which does not match any known method.
1263    #[non_exhaustive]
1264    _UnknownMethod {
1265        /// Ordinal of the method that was called.
1266        ordinal: u64,
1267        control_handle: UsbSourceControlHandle,
1268        method_type: fidl::MethodType,
1269    },
1270}
1271
1272impl UsbSourceRequest {
1273    #[allow(irrefutable_let_patterns)]
1274    pub fn into_get_spec(self) -> Option<(UsbSourceGetSpecResponder)> {
1275        if let UsbSourceRequest::GetSpec { responder } = self { Some((responder)) } else { None }
1276    }
1277
1278    #[allow(irrefutable_let_patterns)]
1279    pub fn into_get_status(self) -> Option<(UsbSourceGetStatusResponder)> {
1280        if let UsbSourceRequest::GetStatus { responder } = self { Some((responder)) } else { None }
1281    }
1282
1283    #[allow(irrefutable_let_patterns)]
1284    pub fn into_set_input_current_limit(
1285        self,
1286    ) -> Option<(u32, UsbSourceSetInputCurrentLimitResponder)> {
1287        if let UsbSourceRequest::SetInputCurrentLimit { limit_ua, responder } = self {
1288            Some((limit_ua, responder))
1289        } else {
1290            None
1291        }
1292    }
1293
1294    #[allow(irrefutable_let_patterns)]
1295    pub fn into_watch(
1296        self,
1297    ) -> Option<(Status, Status, Option<fidl::EventPair>, UsbSourceWatchResponder)> {
1298        if let UsbSourceRequest::Watch { interest, wake_on, lease, responder } = self {
1299            Some((interest, wake_on, lease, responder))
1300        } else {
1301            None
1302        }
1303    }
1304
1305    /// Name of the method defined in FIDL
1306    pub fn method_name(&self) -> &'static str {
1307        match *self {
1308            UsbSourceRequest::GetSpec { .. } => "get_spec",
1309            UsbSourceRequest::GetStatus { .. } => "get_status",
1310            UsbSourceRequest::SetInputCurrentLimit { .. } => "set_input_current_limit",
1311            UsbSourceRequest::Watch { .. } => "watch",
1312            UsbSourceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
1313                "unknown one-way method"
1314            }
1315            UsbSourceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
1316                "unknown two-way method"
1317            }
1318        }
1319    }
1320}
1321
1322#[derive(Debug, Clone)]
1323pub struct UsbSourceControlHandle {
1324    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1325}
1326
1327impl UsbSourceControlHandle {
1328    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1329        self.inner.shutdown_with_epitaph(status.into())
1330    }
1331}
1332
1333impl fidl::endpoints::ControlHandle for UsbSourceControlHandle {
1334    fn shutdown(&self) {
1335        self.inner.shutdown()
1336    }
1337
1338    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1339        self.inner.shutdown_with_epitaph(status)
1340    }
1341
1342    fn is_closed(&self) -> bool {
1343        self.inner.channel().is_closed()
1344    }
1345    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1346        self.inner.channel().on_closed()
1347    }
1348
1349    #[cfg(target_os = "fuchsia")]
1350    fn signal_peer(
1351        &self,
1352        clear_mask: zx::Signals,
1353        set_mask: zx::Signals,
1354    ) -> Result<(), zx_status::Status> {
1355        use fidl::Peered;
1356        self.inner.channel().signal_peer(clear_mask, set_mask)
1357    }
1358}
1359
1360impl UsbSourceControlHandle {}
1361
1362#[must_use = "FIDL methods require a response to be sent"]
1363#[derive(Debug)]
1364pub struct UsbSourceGetSpecResponder {
1365    control_handle: std::mem::ManuallyDrop<UsbSourceControlHandle>,
1366    tx_id: u32,
1367}
1368
1369/// Set the the channel to be shutdown (see [`UsbSourceControlHandle::shutdown`])
1370/// if the responder is dropped without sending a response, so that the client
1371/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1372impl std::ops::Drop for UsbSourceGetSpecResponder {
1373    fn drop(&mut self) {
1374        self.control_handle.shutdown();
1375        // Safety: drops once, never accessed again
1376        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1377    }
1378}
1379
1380impl fidl::endpoints::Responder for UsbSourceGetSpecResponder {
1381    type ControlHandle = UsbSourceControlHandle;
1382
1383    fn control_handle(&self) -> &UsbSourceControlHandle {
1384        &self.control_handle
1385    }
1386
1387    fn drop_without_shutdown(mut self) {
1388        // Safety: drops once, never accessed again due to mem::forget
1389        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1390        // Prevent Drop from running (which would shut down the channel)
1391        std::mem::forget(self);
1392    }
1393}
1394
1395impl UsbSourceGetSpecResponder {
1396    /// Sends a response to the FIDL transaction.
1397    ///
1398    /// Sets the channel to shutdown if an error occurs.
1399    pub fn send(
1400        self,
1401        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
1402    ) -> Result<(), fidl::Error> {
1403        let _result = self.send_raw(result);
1404        if _result.is_err() {
1405            self.control_handle.shutdown();
1406        }
1407        self.drop_without_shutdown();
1408        _result
1409    }
1410
1411    /// Similar to "send" but does not shutdown the channel if an error occurs.
1412    pub fn send_no_shutdown_on_err(
1413        self,
1414        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
1415    ) -> Result<(), fidl::Error> {
1416        let _result = self.send_raw(result);
1417        self.drop_without_shutdown();
1418        _result
1419    }
1420
1421    fn send_raw(
1422        &self,
1423        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
1424    ) -> Result<(), fidl::Error> {
1425        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1426            UsbSourceGetSpecResponse,
1427            fidl_fuchsia_hardware_power_source::Error,
1428        >>(
1429            fidl::encoding::FlexibleResult::new(result.map(|spec| (spec,))),
1430            self.tx_id,
1431            0xa6da1fd32ae9e5e,
1432            fidl::encoding::DynamicFlags::FLEXIBLE,
1433        )
1434    }
1435}
1436
1437#[must_use = "FIDL methods require a response to be sent"]
1438#[derive(Debug)]
1439pub struct UsbSourceGetStatusResponder {
1440    control_handle: std::mem::ManuallyDrop<UsbSourceControlHandle>,
1441    tx_id: u32,
1442}
1443
1444/// Set the the channel to be shutdown (see [`UsbSourceControlHandle::shutdown`])
1445/// if the responder is dropped without sending a response, so that the client
1446/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1447impl std::ops::Drop for UsbSourceGetStatusResponder {
1448    fn drop(&mut self) {
1449        self.control_handle.shutdown();
1450        // Safety: drops once, never accessed again
1451        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1452    }
1453}
1454
1455impl fidl::endpoints::Responder for UsbSourceGetStatusResponder {
1456    type ControlHandle = UsbSourceControlHandle;
1457
1458    fn control_handle(&self) -> &UsbSourceControlHandle {
1459        &self.control_handle
1460    }
1461
1462    fn drop_without_shutdown(mut self) {
1463        // Safety: drops once, never accessed again due to mem::forget
1464        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1465        // Prevent Drop from running (which would shut down the channel)
1466        std::mem::forget(self);
1467    }
1468}
1469
1470impl UsbSourceGetStatusResponder {
1471    /// Sends a response to the FIDL transaction.
1472    ///
1473    /// Sets the channel to shutdown if an error occurs.
1474    pub fn send(
1475        self,
1476        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
1477    ) -> Result<(), fidl::Error> {
1478        let _result = self.send_raw(result);
1479        if _result.is_err() {
1480            self.control_handle.shutdown();
1481        }
1482        self.drop_without_shutdown();
1483        _result
1484    }
1485
1486    /// Similar to "send" but does not shutdown the channel if an error occurs.
1487    pub fn send_no_shutdown_on_err(
1488        self,
1489        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
1490    ) -> Result<(), fidl::Error> {
1491        let _result = self.send_raw(result);
1492        self.drop_without_shutdown();
1493        _result
1494    }
1495
1496    fn send_raw(
1497        &self,
1498        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
1499    ) -> Result<(), fidl::Error> {
1500        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1501            UsbSourceGetStatusResponse,
1502            fidl_fuchsia_hardware_power_source::Error,
1503        >>(
1504            fidl::encoding::FlexibleResult::new(result.map(|status| (status,))),
1505            self.tx_id,
1506            0x48d44a3f9b92471a,
1507            fidl::encoding::DynamicFlags::FLEXIBLE,
1508        )
1509    }
1510}
1511
1512#[must_use = "FIDL methods require a response to be sent"]
1513#[derive(Debug)]
1514pub struct UsbSourceSetInputCurrentLimitResponder {
1515    control_handle: std::mem::ManuallyDrop<UsbSourceControlHandle>,
1516    tx_id: u32,
1517}
1518
1519/// Set the the channel to be shutdown (see [`UsbSourceControlHandle::shutdown`])
1520/// if the responder is dropped without sending a response, so that the client
1521/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1522impl std::ops::Drop for UsbSourceSetInputCurrentLimitResponder {
1523    fn drop(&mut self) {
1524        self.control_handle.shutdown();
1525        // Safety: drops once, never accessed again
1526        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1527    }
1528}
1529
1530impl fidl::endpoints::Responder for UsbSourceSetInputCurrentLimitResponder {
1531    type ControlHandle = UsbSourceControlHandle;
1532
1533    fn control_handle(&self) -> &UsbSourceControlHandle {
1534        &self.control_handle
1535    }
1536
1537    fn drop_without_shutdown(mut self) {
1538        // Safety: drops once, never accessed again due to mem::forget
1539        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1540        // Prevent Drop from running (which would shut down the channel)
1541        std::mem::forget(self);
1542    }
1543}
1544
1545impl UsbSourceSetInputCurrentLimitResponder {
1546    /// Sends a response to the FIDL transaction.
1547    ///
1548    /// Sets the channel to shutdown if an error occurs.
1549    pub fn send(
1550        self,
1551        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
1552    ) -> Result<(), fidl::Error> {
1553        let _result = self.send_raw(result);
1554        if _result.is_err() {
1555            self.control_handle.shutdown();
1556        }
1557        self.drop_without_shutdown();
1558        _result
1559    }
1560
1561    /// Similar to "send" but does not shutdown the channel if an error occurs.
1562    pub fn send_no_shutdown_on_err(
1563        self,
1564        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
1565    ) -> Result<(), fidl::Error> {
1566        let _result = self.send_raw(result);
1567        self.drop_without_shutdown();
1568        _result
1569    }
1570
1571    fn send_raw(
1572        &self,
1573        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
1574    ) -> Result<(), fidl::Error> {
1575        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1576            fidl::encoding::EmptyStruct,
1577            fidl_fuchsia_hardware_power_source::Error,
1578        >>(
1579            fidl::encoding::FlexibleResult::new(result),
1580            self.tx_id,
1581            0x7633140057298018,
1582            fidl::encoding::DynamicFlags::FLEXIBLE,
1583        )
1584    }
1585}
1586
1587#[must_use = "FIDL methods require a response to be sent"]
1588#[derive(Debug)]
1589pub struct UsbSourceWatchResponder {
1590    control_handle: std::mem::ManuallyDrop<UsbSourceControlHandle>,
1591    tx_id: u32,
1592}
1593
1594/// Set the the channel to be shutdown (see [`UsbSourceControlHandle::shutdown`])
1595/// if the responder is dropped without sending a response, so that the client
1596/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1597impl std::ops::Drop for UsbSourceWatchResponder {
1598    fn drop(&mut self) {
1599        self.control_handle.shutdown();
1600        // Safety: drops once, never accessed again
1601        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1602    }
1603}
1604
1605impl fidl::endpoints::Responder for UsbSourceWatchResponder {
1606    type ControlHandle = UsbSourceControlHandle;
1607
1608    fn control_handle(&self) -> &UsbSourceControlHandle {
1609        &self.control_handle
1610    }
1611
1612    fn drop_without_shutdown(mut self) {
1613        // Safety: drops once, never accessed again due to mem::forget
1614        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1615        // Prevent Drop from running (which would shut down the channel)
1616        std::mem::forget(self);
1617    }
1618}
1619
1620impl UsbSourceWatchResponder {
1621    /// Sends a response to the FIDL transaction.
1622    ///
1623    /// Sets the channel to shutdown if an error occurs.
1624    pub fn send(
1625        self,
1626        mut result: Result<
1627            (&Status, Option<fidl::EventPair>),
1628            fidl_fuchsia_hardware_power_source::Error,
1629        >,
1630    ) -> Result<(), fidl::Error> {
1631        let _result = self.send_raw(result);
1632        if _result.is_err() {
1633            self.control_handle.shutdown();
1634        }
1635        self.drop_without_shutdown();
1636        _result
1637    }
1638
1639    /// Similar to "send" but does not shutdown the channel if an error occurs.
1640    pub fn send_no_shutdown_on_err(
1641        self,
1642        mut result: Result<
1643            (&Status, Option<fidl::EventPair>),
1644            fidl_fuchsia_hardware_power_source::Error,
1645        >,
1646    ) -> Result<(), fidl::Error> {
1647        let _result = self.send_raw(result);
1648        self.drop_without_shutdown();
1649        _result
1650    }
1651
1652    fn send_raw(
1653        &self,
1654        mut result: Result<
1655            (&Status, Option<fidl::EventPair>),
1656            fidl_fuchsia_hardware_power_source::Error,
1657        >,
1658    ) -> Result<(), fidl::Error> {
1659        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1660            UsbSourceWatchResponse,
1661            fidl_fuchsia_hardware_power_source::Error,
1662        >>(
1663            fidl::encoding::FlexibleResult::new(result),
1664            self.tx_id,
1665            0x740e01eea4327def,
1666            fidl::encoding::DynamicFlags::FLEXIBLE,
1667        )
1668    }
1669}
1670
1671#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1672pub struct DebugServiceMarker;
1673
1674#[cfg(target_os = "fuchsia")]
1675impl fidl::endpoints::ServiceMarker for DebugServiceMarker {
1676    type Proxy = DebugServiceProxy;
1677    type Request = DebugServiceRequest;
1678    const SERVICE_NAME: &'static str = "fuchsia.hardware.power.usb.DebugService";
1679}
1680
1681/// A request for one of the member protocols of DebugService.
1682///
1683#[cfg(target_os = "fuchsia")]
1684pub enum DebugServiceRequest {
1685    Debug(DebugRequestStream),
1686}
1687
1688#[cfg(target_os = "fuchsia")]
1689impl fidl::endpoints::ServiceRequest for DebugServiceRequest {
1690    type Service = DebugServiceMarker;
1691
1692    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1693        match name {
1694            "debug" => Self::Debug(
1695                <DebugRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1696            ),
1697            _ => panic!("no such member protocol name for service DebugService"),
1698        }
1699    }
1700
1701    fn member_names() -> &'static [&'static str] {
1702        &["debug"]
1703    }
1704}
1705#[cfg(target_os = "fuchsia")]
1706pub struct DebugServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1707
1708#[cfg(target_os = "fuchsia")]
1709impl fidl::endpoints::ServiceProxy for DebugServiceProxy {
1710    type Service = DebugServiceMarker;
1711
1712    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1713        Self(opener)
1714    }
1715}
1716
1717#[cfg(target_os = "fuchsia")]
1718impl DebugServiceProxy {
1719    pub fn connect_to_debug(&self) -> Result<DebugProxy, fidl::Error> {
1720        let (proxy, server_end) = fidl::endpoints::create_proxy::<DebugMarker>();
1721        self.connect_channel_to_debug(server_end)?;
1722        Ok(proxy)
1723    }
1724
1725    /// Like `connect_to_debug`, but returns a sync proxy.
1726    /// See [`Self::connect_to_debug`] for more details.
1727    pub fn connect_to_debug_sync(&self) -> Result<DebugSynchronousProxy, fidl::Error> {
1728        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DebugMarker>();
1729        self.connect_channel_to_debug(server_end)?;
1730        Ok(proxy)
1731    }
1732
1733    /// Like `connect_to_debug`, but accepts a server end.
1734    /// See [`Self::connect_to_debug`] for more details.
1735    pub fn connect_channel_to_debug(
1736        &self,
1737        server_end: fidl::endpoints::ServerEnd<DebugMarker>,
1738    ) -> Result<(), fidl::Error> {
1739        self.0.open_member("debug", server_end.into_channel())
1740    }
1741
1742    pub fn instance_name(&self) -> &str {
1743        self.0.instance_name()
1744    }
1745}
1746
1747#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1748pub struct ServiceMarker;
1749
1750#[cfg(target_os = "fuchsia")]
1751impl fidl::endpoints::ServiceMarker for ServiceMarker {
1752    type Proxy = ServiceProxy;
1753    type Request = ServiceRequest;
1754    const SERVICE_NAME: &'static str = "fuchsia.hardware.power.usb.Service";
1755}
1756
1757/// A request for one of the member protocols of Service.
1758///
1759#[cfg(target_os = "fuchsia")]
1760pub enum ServiceRequest {
1761    Usb(UsbSourceRequestStream),
1762    PowerSource(fidl_fuchsia_hardware_power_source::SourceRequestStream),
1763}
1764
1765#[cfg(target_os = "fuchsia")]
1766impl fidl::endpoints::ServiceRequest for ServiceRequest {
1767    type Service = ServiceMarker;
1768
1769    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1770        match name {
1771            "usb" => Self::Usb(
1772                <UsbSourceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1773            ),
1774            "power_source" => Self::PowerSource(
1775                <fidl_fuchsia_hardware_power_source::SourceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1776            ),
1777            _ => panic!("no such member protocol name for service Service"),
1778        }
1779    }
1780
1781    fn member_names() -> &'static [&'static str] {
1782        &["usb", "power_source"]
1783    }
1784}
1785#[cfg(target_os = "fuchsia")]
1786pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1787
1788#[cfg(target_os = "fuchsia")]
1789impl fidl::endpoints::ServiceProxy for ServiceProxy {
1790    type Service = ServiceMarker;
1791
1792    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1793        Self(opener)
1794    }
1795}
1796
1797#[cfg(target_os = "fuchsia")]
1798impl ServiceProxy {
1799    pub fn connect_to_usb(&self) -> Result<UsbSourceProxy, fidl::Error> {
1800        let (proxy, server_end) = fidl::endpoints::create_proxy::<UsbSourceMarker>();
1801        self.connect_channel_to_usb(server_end)?;
1802        Ok(proxy)
1803    }
1804
1805    /// Like `connect_to_usb`, but returns a sync proxy.
1806    /// See [`Self::connect_to_usb`] for more details.
1807    pub fn connect_to_usb_sync(&self) -> Result<UsbSourceSynchronousProxy, fidl::Error> {
1808        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<UsbSourceMarker>();
1809        self.connect_channel_to_usb(server_end)?;
1810        Ok(proxy)
1811    }
1812
1813    /// Like `connect_to_usb`, but accepts a server end.
1814    /// See [`Self::connect_to_usb`] for more details.
1815    pub fn connect_channel_to_usb(
1816        &self,
1817        server_end: fidl::endpoints::ServerEnd<UsbSourceMarker>,
1818    ) -> Result<(), fidl::Error> {
1819        self.0.open_member("usb", server_end.into_channel())
1820    }
1821    pub fn connect_to_power_source(
1822        &self,
1823    ) -> Result<fidl_fuchsia_hardware_power_source::SourceProxy, fidl::Error> {
1824        let (proxy, server_end) =
1825            fidl::endpoints::create_proxy::<fidl_fuchsia_hardware_power_source::SourceMarker>();
1826        self.connect_channel_to_power_source(server_end)?;
1827        Ok(proxy)
1828    }
1829
1830    /// Like `connect_to_power_source`, but returns a sync proxy.
1831    /// See [`Self::connect_to_power_source`] for more details.
1832    pub fn connect_to_power_source_sync(
1833        &self,
1834    ) -> Result<fidl_fuchsia_hardware_power_source::SourceSynchronousProxy, fidl::Error> {
1835        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<
1836            fidl_fuchsia_hardware_power_source::SourceMarker,
1837        >();
1838        self.connect_channel_to_power_source(server_end)?;
1839        Ok(proxy)
1840    }
1841
1842    /// Like `connect_to_power_source`, but accepts a server end.
1843    /// See [`Self::connect_to_power_source`] for more details.
1844    pub fn connect_channel_to_power_source(
1845        &self,
1846        server_end: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_power_source::SourceMarker>,
1847    ) -> Result<(), fidl::Error> {
1848        self.0.open_member("power_source", server_end.into_channel())
1849    }
1850
1851    pub fn instance_name(&self) -> &str {
1852        self.0.instance_name()
1853    }
1854}
1855
1856mod internal {
1857    use super::*;
1858
1859    impl fidl::encoding::ResourceTypeMarker for DebugSetConnectedRequest {
1860        type Borrowed<'a> = &'a mut Self;
1861        fn take_or_borrow<'a>(
1862            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1863        ) -> Self::Borrowed<'a> {
1864            value
1865        }
1866    }
1867
1868    unsafe impl fidl::encoding::TypeMarker for DebugSetConnectedRequest {
1869        type Owned = Self;
1870
1871        #[inline(always)]
1872        fn inline_align(_context: fidl::encoding::Context) -> usize {
1873            4
1874        }
1875
1876        #[inline(always)]
1877        fn inline_size(_context: fidl::encoding::Context) -> usize {
1878            8
1879        }
1880    }
1881
1882    unsafe impl
1883        fidl::encoding::Encode<
1884            DebugSetConnectedRequest,
1885            fidl::encoding::DefaultFuchsiaResourceDialect,
1886        > for &mut DebugSetConnectedRequest
1887    {
1888        #[inline]
1889        unsafe fn encode(
1890            self,
1891            encoder: &mut fidl::encoding::Encoder<
1892                '_,
1893                fidl::encoding::DefaultFuchsiaResourceDialect,
1894            >,
1895            offset: usize,
1896            _depth: fidl::encoding::Depth,
1897        ) -> fidl::Result<()> {
1898            encoder.debug_check_bounds::<DebugSetConnectedRequest>(offset);
1899            // Delegate to tuple encoding.
1900            fidl::encoding::Encode::<
1901                DebugSetConnectedRequest,
1902                fidl::encoding::DefaultFuchsiaResourceDialect,
1903            >::encode(
1904                (
1905                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.connected),
1906                    <fidl::encoding::Optional<
1907                        fidl::encoding::HandleType<
1908                            fidl::EventPair,
1909                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1910                            16387,
1911                        >,
1912                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1913                        &mut self.wake_lease
1914                    ),
1915                ),
1916                encoder,
1917                offset,
1918                _depth,
1919            )
1920        }
1921    }
1922    unsafe impl<
1923        T0: fidl::encoding::Encode<bool, fidl::encoding::DefaultFuchsiaResourceDialect>,
1924        T1: fidl::encoding::Encode<
1925                fidl::encoding::Optional<
1926                    fidl::encoding::HandleType<
1927                        fidl::EventPair,
1928                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1929                        16387,
1930                    >,
1931                >,
1932                fidl::encoding::DefaultFuchsiaResourceDialect,
1933            >,
1934    >
1935        fidl::encoding::Encode<
1936            DebugSetConnectedRequest,
1937            fidl::encoding::DefaultFuchsiaResourceDialect,
1938        > for (T0, T1)
1939    {
1940        #[inline]
1941        unsafe fn encode(
1942            self,
1943            encoder: &mut fidl::encoding::Encoder<
1944                '_,
1945                fidl::encoding::DefaultFuchsiaResourceDialect,
1946            >,
1947            offset: usize,
1948            depth: fidl::encoding::Depth,
1949        ) -> fidl::Result<()> {
1950            encoder.debug_check_bounds::<DebugSetConnectedRequest>(offset);
1951            // Zero out padding regions. There's no need to apply masks
1952            // because the unmasked parts will be overwritten by fields.
1953            unsafe {
1954                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
1955                (ptr as *mut u32).write_unaligned(0);
1956            }
1957            // Write the fields.
1958            self.0.encode(encoder, offset + 0, depth)?;
1959            self.1.encode(encoder, offset + 4, depth)?;
1960            Ok(())
1961        }
1962    }
1963
1964    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1965        for DebugSetConnectedRequest
1966    {
1967        #[inline(always)]
1968        fn new_empty() -> Self {
1969            Self {
1970                connected: fidl::new_empty!(bool, fidl::encoding::DefaultFuchsiaResourceDialect),
1971                wake_lease: fidl::new_empty!(
1972                    fidl::encoding::Optional<
1973                        fidl::encoding::HandleType<
1974                            fidl::EventPair,
1975                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1976                            16387,
1977                        >,
1978                    >,
1979                    fidl::encoding::DefaultFuchsiaResourceDialect
1980                ),
1981            }
1982        }
1983
1984        #[inline]
1985        unsafe fn decode(
1986            &mut self,
1987            decoder: &mut fidl::encoding::Decoder<
1988                '_,
1989                fidl::encoding::DefaultFuchsiaResourceDialect,
1990            >,
1991            offset: usize,
1992            _depth: fidl::encoding::Depth,
1993        ) -> fidl::Result<()> {
1994            decoder.debug_check_bounds::<Self>(offset);
1995            // Verify that padding bytes are zero.
1996            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
1997            let padval = unsafe { (ptr as *const u32).read_unaligned() };
1998            let mask = 0xffffff00u32;
1999            let maskedval = padval & mask;
2000            if maskedval != 0 {
2001                return Err(fidl::Error::NonZeroPadding {
2002                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
2003                });
2004            }
2005            fidl::decode!(
2006                bool,
2007                fidl::encoding::DefaultFuchsiaResourceDialect,
2008                &mut self.connected,
2009                decoder,
2010                offset + 0,
2011                _depth
2012            )?;
2013            fidl::decode!(
2014                fidl::encoding::Optional<
2015                    fidl::encoding::HandleType<
2016                        fidl::EventPair,
2017                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2018                        16387,
2019                    >,
2020                >,
2021                fidl::encoding::DefaultFuchsiaResourceDialect,
2022                &mut self.wake_lease,
2023                decoder,
2024                offset + 4,
2025                _depth
2026            )?;
2027            Ok(())
2028        }
2029    }
2030
2031    impl fidl::encoding::ResourceTypeMarker for UsbSourceWatchRequest {
2032        type Borrowed<'a> = &'a mut Self;
2033        fn take_or_borrow<'a>(
2034            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2035        ) -> Self::Borrowed<'a> {
2036            value
2037        }
2038    }
2039
2040    unsafe impl fidl::encoding::TypeMarker for UsbSourceWatchRequest {
2041        type Owned = Self;
2042
2043        #[inline(always)]
2044        fn inline_align(_context: fidl::encoding::Context) -> usize {
2045            8
2046        }
2047
2048        #[inline(always)]
2049        fn inline_size(_context: fidl::encoding::Context) -> usize {
2050            40
2051        }
2052    }
2053
2054    unsafe impl
2055        fidl::encoding::Encode<UsbSourceWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
2056        for &mut UsbSourceWatchRequest
2057    {
2058        #[inline]
2059        unsafe fn encode(
2060            self,
2061            encoder: &mut fidl::encoding::Encoder<
2062                '_,
2063                fidl::encoding::DefaultFuchsiaResourceDialect,
2064            >,
2065            offset: usize,
2066            _depth: fidl::encoding::Depth,
2067        ) -> fidl::Result<()> {
2068            encoder.debug_check_bounds::<UsbSourceWatchRequest>(offset);
2069            // Delegate to tuple encoding.
2070            fidl::encoding::Encode::<
2071                UsbSourceWatchRequest,
2072                fidl::encoding::DefaultFuchsiaResourceDialect,
2073            >::encode(
2074                (
2075                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.interest),
2076                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.wake_on),
2077                    <fidl::encoding::Optional<
2078                        fidl::encoding::HandleType<
2079                            fidl::EventPair,
2080                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2081                            16387,
2082                        >,
2083                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
2084                        &mut self.lease
2085                    ),
2086                ),
2087                encoder,
2088                offset,
2089                _depth,
2090            )
2091        }
2092    }
2093    unsafe impl<
2094        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
2095        T1: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
2096        T2: fidl::encoding::Encode<
2097                fidl::encoding::Optional<
2098                    fidl::encoding::HandleType<
2099                        fidl::EventPair,
2100                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2101                        16387,
2102                    >,
2103                >,
2104                fidl::encoding::DefaultFuchsiaResourceDialect,
2105            >,
2106    >
2107        fidl::encoding::Encode<UsbSourceWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
2108        for (T0, T1, T2)
2109    {
2110        #[inline]
2111        unsafe fn encode(
2112            self,
2113            encoder: &mut fidl::encoding::Encoder<
2114                '_,
2115                fidl::encoding::DefaultFuchsiaResourceDialect,
2116            >,
2117            offset: usize,
2118            depth: fidl::encoding::Depth,
2119        ) -> fidl::Result<()> {
2120            encoder.debug_check_bounds::<UsbSourceWatchRequest>(offset);
2121            // Zero out padding regions. There's no need to apply masks
2122            // because the unmasked parts will be overwritten by fields.
2123            unsafe {
2124                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
2125                (ptr as *mut u64).write_unaligned(0);
2126            }
2127            // Write the fields.
2128            self.0.encode(encoder, offset + 0, depth)?;
2129            self.1.encode(encoder, offset + 16, depth)?;
2130            self.2.encode(encoder, offset + 32, depth)?;
2131            Ok(())
2132        }
2133    }
2134
2135    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2136        for UsbSourceWatchRequest
2137    {
2138        #[inline(always)]
2139        fn new_empty() -> Self {
2140            Self {
2141                interest: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
2142                wake_on: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
2143                lease: fidl::new_empty!(
2144                    fidl::encoding::Optional<
2145                        fidl::encoding::HandleType<
2146                            fidl::EventPair,
2147                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2148                            16387,
2149                        >,
2150                    >,
2151                    fidl::encoding::DefaultFuchsiaResourceDialect
2152                ),
2153            }
2154        }
2155
2156        #[inline]
2157        unsafe fn decode(
2158            &mut self,
2159            decoder: &mut fidl::encoding::Decoder<
2160                '_,
2161                fidl::encoding::DefaultFuchsiaResourceDialect,
2162            >,
2163            offset: usize,
2164            _depth: fidl::encoding::Depth,
2165        ) -> fidl::Result<()> {
2166            decoder.debug_check_bounds::<Self>(offset);
2167            // Verify that padding bytes are zero.
2168            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
2169            let padval = unsafe { (ptr as *const u64).read_unaligned() };
2170            let mask = 0xffffffff00000000u64;
2171            let maskedval = padval & mask;
2172            if maskedval != 0 {
2173                return Err(fidl::Error::NonZeroPadding {
2174                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
2175                });
2176            }
2177            fidl::decode!(
2178                Status,
2179                fidl::encoding::DefaultFuchsiaResourceDialect,
2180                &mut self.interest,
2181                decoder,
2182                offset + 0,
2183                _depth
2184            )?;
2185            fidl::decode!(
2186                Status,
2187                fidl::encoding::DefaultFuchsiaResourceDialect,
2188                &mut self.wake_on,
2189                decoder,
2190                offset + 16,
2191                _depth
2192            )?;
2193            fidl::decode!(
2194                fidl::encoding::Optional<
2195                    fidl::encoding::HandleType<
2196                        fidl::EventPair,
2197                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2198                        16387,
2199                    >,
2200                >,
2201                fidl::encoding::DefaultFuchsiaResourceDialect,
2202                &mut self.lease,
2203                decoder,
2204                offset + 32,
2205                _depth
2206            )?;
2207            Ok(())
2208        }
2209    }
2210
2211    impl fidl::encoding::ResourceTypeMarker for UsbSourceWatchResponse {
2212        type Borrowed<'a> = &'a mut Self;
2213        fn take_or_borrow<'a>(
2214            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2215        ) -> Self::Borrowed<'a> {
2216            value
2217        }
2218    }
2219
2220    unsafe impl fidl::encoding::TypeMarker for UsbSourceWatchResponse {
2221        type Owned = Self;
2222
2223        #[inline(always)]
2224        fn inline_align(_context: fidl::encoding::Context) -> usize {
2225            8
2226        }
2227
2228        #[inline(always)]
2229        fn inline_size(_context: fidl::encoding::Context) -> usize {
2230            24
2231        }
2232    }
2233
2234    unsafe impl
2235        fidl::encoding::Encode<
2236            UsbSourceWatchResponse,
2237            fidl::encoding::DefaultFuchsiaResourceDialect,
2238        > for &mut UsbSourceWatchResponse
2239    {
2240        #[inline]
2241        unsafe fn encode(
2242            self,
2243            encoder: &mut fidl::encoding::Encoder<
2244                '_,
2245                fidl::encoding::DefaultFuchsiaResourceDialect,
2246            >,
2247            offset: usize,
2248            _depth: fidl::encoding::Depth,
2249        ) -> fidl::Result<()> {
2250            encoder.debug_check_bounds::<UsbSourceWatchResponse>(offset);
2251            // Delegate to tuple encoding.
2252            fidl::encoding::Encode::<
2253                UsbSourceWatchResponse,
2254                fidl::encoding::DefaultFuchsiaResourceDialect,
2255            >::encode(
2256                (
2257                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
2258                    <fidl::encoding::Optional<
2259                        fidl::encoding::HandleType<
2260                            fidl::EventPair,
2261                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2262                            16387,
2263                        >,
2264                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
2265                        &mut self.wake_lease
2266                    ),
2267                ),
2268                encoder,
2269                offset,
2270                _depth,
2271            )
2272        }
2273    }
2274    unsafe impl<
2275        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
2276        T1: fidl::encoding::Encode<
2277                fidl::encoding::Optional<
2278                    fidl::encoding::HandleType<
2279                        fidl::EventPair,
2280                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2281                        16387,
2282                    >,
2283                >,
2284                fidl::encoding::DefaultFuchsiaResourceDialect,
2285            >,
2286    >
2287        fidl::encoding::Encode<
2288            UsbSourceWatchResponse,
2289            fidl::encoding::DefaultFuchsiaResourceDialect,
2290        > for (T0, T1)
2291    {
2292        #[inline]
2293        unsafe fn encode(
2294            self,
2295            encoder: &mut fidl::encoding::Encoder<
2296                '_,
2297                fidl::encoding::DefaultFuchsiaResourceDialect,
2298            >,
2299            offset: usize,
2300            depth: fidl::encoding::Depth,
2301        ) -> fidl::Result<()> {
2302            encoder.debug_check_bounds::<UsbSourceWatchResponse>(offset);
2303            // Zero out padding regions. There's no need to apply masks
2304            // because the unmasked parts will be overwritten by fields.
2305            unsafe {
2306                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
2307                (ptr as *mut u64).write_unaligned(0);
2308            }
2309            // Write the fields.
2310            self.0.encode(encoder, offset + 0, depth)?;
2311            self.1.encode(encoder, offset + 16, depth)?;
2312            Ok(())
2313        }
2314    }
2315
2316    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2317        for UsbSourceWatchResponse
2318    {
2319        #[inline(always)]
2320        fn new_empty() -> Self {
2321            Self {
2322                status: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
2323                wake_lease: fidl::new_empty!(
2324                    fidl::encoding::Optional<
2325                        fidl::encoding::HandleType<
2326                            fidl::EventPair,
2327                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2328                            16387,
2329                        >,
2330                    >,
2331                    fidl::encoding::DefaultFuchsiaResourceDialect
2332                ),
2333            }
2334        }
2335
2336        #[inline]
2337        unsafe fn decode(
2338            &mut self,
2339            decoder: &mut fidl::encoding::Decoder<
2340                '_,
2341                fidl::encoding::DefaultFuchsiaResourceDialect,
2342            >,
2343            offset: usize,
2344            _depth: fidl::encoding::Depth,
2345        ) -> fidl::Result<()> {
2346            decoder.debug_check_bounds::<Self>(offset);
2347            // Verify that padding bytes are zero.
2348            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
2349            let padval = unsafe { (ptr as *const u64).read_unaligned() };
2350            let mask = 0xffffffff00000000u64;
2351            let maskedval = padval & mask;
2352            if maskedval != 0 {
2353                return Err(fidl::Error::NonZeroPadding {
2354                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
2355                });
2356            }
2357            fidl::decode!(
2358                Status,
2359                fidl::encoding::DefaultFuchsiaResourceDialect,
2360                &mut self.status,
2361                decoder,
2362                offset + 0,
2363                _depth
2364            )?;
2365            fidl::decode!(
2366                fidl::encoding::Optional<
2367                    fidl::encoding::HandleType<
2368                        fidl::EventPair,
2369                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2370                        16387,
2371                    >,
2372                >,
2373                fidl::encoding::DefaultFuchsiaResourceDialect,
2374                &mut self.wake_lease,
2375                decoder,
2376                offset + 16,
2377                _depth
2378            )?;
2379            Ok(())
2380        }
2381    }
2382}