Skip to main content

fidl_fuchsia_hardware_power_charger/
fidl_fuchsia_hardware_power_charger.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_charger_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct ChargerWatchRequest {
16    pub interest: Status,
17    pub wake_on: Status,
18    pub lease: Option<fidl::EventPair>,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ChargerWatchRequest {}
22
23#[derive(Debug, PartialEq)]
24pub struct ChargerWatchResponse {
25    pub status: Status,
26    pub wake_lease: Option<fidl::EventPair>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ChargerWatchResponse {}
30
31#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
32pub struct ChargerMarker;
33
34impl fidl::endpoints::ProtocolMarker for ChargerMarker {
35    type Proxy = ChargerProxy;
36    type RequestStream = ChargerRequestStream;
37    #[cfg(target_os = "fuchsia")]
38    type SynchronousProxy = ChargerSynchronousProxy;
39
40    const DEBUG_NAME: &'static str = "fuchsia.hardware.power.charger.Charger";
41}
42impl fidl::endpoints::DiscoverableProtocolMarker for ChargerMarker {}
43pub type ChargerGetSpecResult = Result<Spec, fidl_fuchsia_hardware_power_source::Error>;
44pub type ChargerGetStatusResult = Result<Status, fidl_fuchsia_hardware_power_source::Error>;
45pub type ChargerSetChargingEnabledResult = Result<(), fidl_fuchsia_hardware_power_source::Error>;
46pub type ChargerWatchResult =
47    Result<(Status, Option<fidl::EventPair>), fidl_fuchsia_hardware_power_source::Error>;
48
49pub trait ChargerProxyInterface: Send + Sync {
50    type GetSpecResponseFut: std::future::Future<Output = Result<ChargerGetSpecResult, fidl::Error>>
51        + Send;
52    fn r#get_spec(&self) -> Self::GetSpecResponseFut;
53    type GetStatusResponseFut: std::future::Future<Output = Result<ChargerGetStatusResult, fidl::Error>>
54        + Send;
55    fn r#get_status(&self) -> Self::GetStatusResponseFut;
56    type SetChargingEnabledResponseFut: std::future::Future<Output = Result<ChargerSetChargingEnabledResult, fidl::Error>>
57        + Send;
58    fn r#set_charging_enabled(&self, enabled: bool) -> Self::SetChargingEnabledResponseFut;
59    type WatchResponseFut: std::future::Future<Output = Result<ChargerWatchResult, fidl::Error>>
60        + Send;
61    fn r#watch(
62        &self,
63        interest: &Status,
64        wake_on: &Status,
65        lease: Option<fidl::EventPair>,
66    ) -> Self::WatchResponseFut;
67}
68#[derive(Debug)]
69#[cfg(target_os = "fuchsia")]
70pub struct ChargerSynchronousProxy {
71    client: fidl::client::sync::Client,
72}
73
74#[cfg(target_os = "fuchsia")]
75impl fidl::endpoints::SynchronousProxy for ChargerSynchronousProxy {
76    type Proxy = ChargerProxy;
77    type Protocol = ChargerMarker;
78
79    fn from_channel(inner: fidl::Channel) -> Self {
80        Self::new(inner)
81    }
82
83    fn into_channel(self) -> fidl::Channel {
84        self.client.into_channel()
85    }
86
87    fn as_channel(&self) -> &fidl::Channel {
88        self.client.as_channel()
89    }
90}
91
92#[cfg(target_os = "fuchsia")]
93impl ChargerSynchronousProxy {
94    pub fn new(channel: fidl::Channel) -> Self {
95        Self { client: fidl::client::sync::Client::new(channel) }
96    }
97
98    pub fn into_channel(self) -> fidl::Channel {
99        self.client.into_channel()
100    }
101
102    /// Waits until an event arrives and returns it. It is safe for other
103    /// threads to make concurrent requests while waiting for an event.
104    pub fn wait_for_event(
105        &self,
106        deadline: zx::MonotonicInstant,
107    ) -> Result<ChargerEvent, fidl::Error> {
108        ChargerEvent::decode(self.client.wait_for_event::<ChargerMarker>(deadline)?)
109    }
110
111    /// Returns static hardware characteristics of the charger.
112    pub fn r#get_spec(
113        &self,
114        ___deadline: zx::MonotonicInstant,
115    ) -> Result<ChargerGetSpecResult, fidl::Error> {
116        let _response = self
117            .client
118            .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::FlexibleResultType<
119                ChargerGetSpecResponse,
120                fidl_fuchsia_hardware_power_source::Error,
121            >, ChargerMarker>(
122                (),
123                0x4f1a5fc6df415db3,
124                fidl::encoding::DynamicFlags::FLEXIBLE,
125                ___deadline,
126            )?
127            .into_result::<ChargerMarker>("get_spec")?;
128        Ok(_response.map(|x| x.spec))
129    }
130
131    /// Returns the current dynamic status of the charger immediately.
132    pub fn r#get_status(
133        &self,
134        ___deadline: zx::MonotonicInstant,
135    ) -> Result<ChargerGetStatusResult, fidl::Error> {
136        let _response = self
137            .client
138            .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::FlexibleResultType<
139                ChargerGetStatusResponse,
140                fidl_fuchsia_hardware_power_source::Error,
141            >, ChargerMarker>(
142                (),
143                0x3c67651b7ec14d5e,
144                fidl::encoding::DynamicFlags::FLEXIBLE,
145                ___deadline,
146            )?
147            .into_result::<ChargerMarker>("get_status")?;
148        Ok(_response.map(|x| x.status))
149    }
150
151    /// Control methods.
152    ///
153    /// Errors:
154    /// + `NOT_SUPPORTED`: If the hardware does not support enabling/disabling charging.
155    /// + `INTERNAL`: If an unexpected error occurred.
156    pub fn r#set_charging_enabled(
157        &self,
158        mut enabled: bool,
159        ___deadline: zx::MonotonicInstant,
160    ) -> Result<ChargerSetChargingEnabledResult, fidl::Error> {
161        let _response = self
162            .client
163            .send_query::<ChargerSetChargingEnabledRequest, fidl::encoding::FlexibleResultType<
164                fidl::encoding::EmptyStruct,
165                fidl_fuchsia_hardware_power_source::Error,
166            >, ChargerMarker>(
167                (enabled,),
168                0x282b21c4fe4452db,
169                fidl::encoding::DynamicFlags::FLEXIBLE,
170                ___deadline,
171            )?
172            .into_result::<ChargerMarker>("set_charging_enabled")?;
173        Ok(_response.map(|x| x))
174    }
175
176    /// Change notification for charger state using a "hanging-get" pattern.
177    ///
178    /// Follows the same semantics and power management rules as
179    /// [`fuchsia.hardware.power.source/Source.Watch`].
180    ///
181    /// # Errors
182    ///
183    /// * `ALREADY_BOUND` if `Watch` is called before the previous call completes.
184    pub fn r#watch(
185        &self,
186        mut interest: &Status,
187        mut wake_on: &Status,
188        mut lease: Option<fidl::EventPair>,
189        ___deadline: zx::MonotonicInstant,
190    ) -> Result<ChargerWatchResult, fidl::Error> {
191        let _response = self
192            .client
193            .send_query::<ChargerWatchRequest, fidl::encoding::FlexibleResultType<
194                ChargerWatchResponse,
195                fidl_fuchsia_hardware_power_source::Error,
196            >, ChargerMarker>(
197                (interest, wake_on, lease),
198                0x5a52d95d33d7c66e,
199                fidl::encoding::DynamicFlags::FLEXIBLE,
200                ___deadline,
201            )?
202            .into_result::<ChargerMarker>("watch")?;
203        Ok(_response.map(|x| (x.status, x.wake_lease)))
204    }
205}
206
207#[cfg(target_os = "fuchsia")]
208impl From<ChargerSynchronousProxy> for zx::NullableHandle {
209    fn from(value: ChargerSynchronousProxy) -> Self {
210        value.into_channel().into()
211    }
212}
213
214#[cfg(target_os = "fuchsia")]
215impl From<fidl::Channel> for ChargerSynchronousProxy {
216    fn from(value: fidl::Channel) -> Self {
217        Self::new(value)
218    }
219}
220
221#[cfg(target_os = "fuchsia")]
222impl fidl::endpoints::FromClient for ChargerSynchronousProxy {
223    type Protocol = ChargerMarker;
224
225    fn from_client(value: fidl::endpoints::ClientEnd<ChargerMarker>) -> Self {
226        Self::new(value.into_channel())
227    }
228}
229
230#[derive(Debug, Clone)]
231pub struct ChargerProxy {
232    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
233}
234
235impl fidl::endpoints::Proxy for ChargerProxy {
236    type Protocol = ChargerMarker;
237
238    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
239        Self::new(inner)
240    }
241
242    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
243        self.client.into_channel().map_err(|client| Self { client })
244    }
245
246    fn as_channel(&self) -> &::fidl::AsyncChannel {
247        self.client.as_channel()
248    }
249}
250
251impl ChargerProxy {
252    /// Create a new Proxy for fuchsia.hardware.power.charger/Charger.
253    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
254        let protocol_name = <ChargerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
255        Self { client: fidl::client::Client::new(channel, protocol_name) }
256    }
257
258    /// Get a Stream of events from the remote end of the protocol.
259    ///
260    /// # Panics
261    ///
262    /// Panics if the event stream was already taken.
263    pub fn take_event_stream(&self) -> ChargerEventStream {
264        ChargerEventStream { event_receiver: self.client.take_event_receiver() }
265    }
266
267    /// Returns static hardware characteristics of the charger.
268    pub fn r#get_spec(
269        &self,
270    ) -> fidl::client::QueryResponseFut<
271        ChargerGetSpecResult,
272        fidl::encoding::DefaultFuchsiaResourceDialect,
273    > {
274        ChargerProxyInterface::r#get_spec(self)
275    }
276
277    /// Returns the current dynamic status of the charger immediately.
278    pub fn r#get_status(
279        &self,
280    ) -> fidl::client::QueryResponseFut<
281        ChargerGetStatusResult,
282        fidl::encoding::DefaultFuchsiaResourceDialect,
283    > {
284        ChargerProxyInterface::r#get_status(self)
285    }
286
287    /// Control methods.
288    ///
289    /// Errors:
290    /// + `NOT_SUPPORTED`: If the hardware does not support enabling/disabling charging.
291    /// + `INTERNAL`: If an unexpected error occurred.
292    pub fn r#set_charging_enabled(
293        &self,
294        mut enabled: bool,
295    ) -> fidl::client::QueryResponseFut<
296        ChargerSetChargingEnabledResult,
297        fidl::encoding::DefaultFuchsiaResourceDialect,
298    > {
299        ChargerProxyInterface::r#set_charging_enabled(self, enabled)
300    }
301
302    /// Change notification for charger state using a "hanging-get" pattern.
303    ///
304    /// Follows the same semantics and power management rules as
305    /// [`fuchsia.hardware.power.source/Source.Watch`].
306    ///
307    /// # Errors
308    ///
309    /// * `ALREADY_BOUND` if `Watch` is called before the previous call completes.
310    pub fn r#watch(
311        &self,
312        mut interest: &Status,
313        mut wake_on: &Status,
314        mut lease: Option<fidl::EventPair>,
315    ) -> fidl::client::QueryResponseFut<
316        ChargerWatchResult,
317        fidl::encoding::DefaultFuchsiaResourceDialect,
318    > {
319        ChargerProxyInterface::r#watch(self, interest, wake_on, lease)
320    }
321}
322
323impl ChargerProxyInterface for ChargerProxy {
324    type GetSpecResponseFut = fidl::client::QueryResponseFut<
325        ChargerGetSpecResult,
326        fidl::encoding::DefaultFuchsiaResourceDialect,
327    >;
328    fn r#get_spec(&self) -> Self::GetSpecResponseFut {
329        fn _decode(
330            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
331        ) -> Result<ChargerGetSpecResult, fidl::Error> {
332            let _response = fidl::client::decode_transaction_body::<
333                fidl::encoding::FlexibleResultType<
334                    ChargerGetSpecResponse,
335                    fidl_fuchsia_hardware_power_source::Error,
336                >,
337                fidl::encoding::DefaultFuchsiaResourceDialect,
338                0x4f1a5fc6df415db3,
339            >(_buf?)?
340            .into_result::<ChargerMarker>("get_spec")?;
341            Ok(_response.map(|x| x.spec))
342        }
343        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ChargerGetSpecResult>(
344            (),
345            0x4f1a5fc6df415db3,
346            fidl::encoding::DynamicFlags::FLEXIBLE,
347            _decode,
348        )
349    }
350
351    type GetStatusResponseFut = fidl::client::QueryResponseFut<
352        ChargerGetStatusResult,
353        fidl::encoding::DefaultFuchsiaResourceDialect,
354    >;
355    fn r#get_status(&self) -> Self::GetStatusResponseFut {
356        fn _decode(
357            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
358        ) -> Result<ChargerGetStatusResult, fidl::Error> {
359            let _response = fidl::client::decode_transaction_body::<
360                fidl::encoding::FlexibleResultType<
361                    ChargerGetStatusResponse,
362                    fidl_fuchsia_hardware_power_source::Error,
363                >,
364                fidl::encoding::DefaultFuchsiaResourceDialect,
365                0x3c67651b7ec14d5e,
366            >(_buf?)?
367            .into_result::<ChargerMarker>("get_status")?;
368            Ok(_response.map(|x| x.status))
369        }
370        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ChargerGetStatusResult>(
371            (),
372            0x3c67651b7ec14d5e,
373            fidl::encoding::DynamicFlags::FLEXIBLE,
374            _decode,
375        )
376    }
377
378    type SetChargingEnabledResponseFut = fidl::client::QueryResponseFut<
379        ChargerSetChargingEnabledResult,
380        fidl::encoding::DefaultFuchsiaResourceDialect,
381    >;
382    fn r#set_charging_enabled(&self, mut enabled: bool) -> Self::SetChargingEnabledResponseFut {
383        fn _decode(
384            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
385        ) -> Result<ChargerSetChargingEnabledResult, fidl::Error> {
386            let _response = fidl::client::decode_transaction_body::<
387                fidl::encoding::FlexibleResultType<
388                    fidl::encoding::EmptyStruct,
389                    fidl_fuchsia_hardware_power_source::Error,
390                >,
391                fidl::encoding::DefaultFuchsiaResourceDialect,
392                0x282b21c4fe4452db,
393            >(_buf?)?
394            .into_result::<ChargerMarker>("set_charging_enabled")?;
395            Ok(_response.map(|x| x))
396        }
397        self.client.send_query_and_decode::<
398            ChargerSetChargingEnabledRequest,
399            ChargerSetChargingEnabledResult,
400        >(
401            (enabled,),
402            0x282b21c4fe4452db,
403            fidl::encoding::DynamicFlags::FLEXIBLE,
404            _decode,
405        )
406    }
407
408    type WatchResponseFut = fidl::client::QueryResponseFut<
409        ChargerWatchResult,
410        fidl::encoding::DefaultFuchsiaResourceDialect,
411    >;
412    fn r#watch(
413        &self,
414        mut interest: &Status,
415        mut wake_on: &Status,
416        mut lease: Option<fidl::EventPair>,
417    ) -> Self::WatchResponseFut {
418        fn _decode(
419            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
420        ) -> Result<ChargerWatchResult, fidl::Error> {
421            let _response = fidl::client::decode_transaction_body::<
422                fidl::encoding::FlexibleResultType<
423                    ChargerWatchResponse,
424                    fidl_fuchsia_hardware_power_source::Error,
425                >,
426                fidl::encoding::DefaultFuchsiaResourceDialect,
427                0x5a52d95d33d7c66e,
428            >(_buf?)?
429            .into_result::<ChargerMarker>("watch")?;
430            Ok(_response.map(|x| (x.status, x.wake_lease)))
431        }
432        self.client.send_query_and_decode::<ChargerWatchRequest, ChargerWatchResult>(
433            (interest, wake_on, lease),
434            0x5a52d95d33d7c66e,
435            fidl::encoding::DynamicFlags::FLEXIBLE,
436            _decode,
437        )
438    }
439}
440
441pub struct ChargerEventStream {
442    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
443}
444
445impl std::marker::Unpin for ChargerEventStream {}
446
447impl futures::stream::FusedStream for ChargerEventStream {
448    fn is_terminated(&self) -> bool {
449        self.event_receiver.is_terminated()
450    }
451}
452
453impl futures::Stream for ChargerEventStream {
454    type Item = Result<ChargerEvent, fidl::Error>;
455
456    fn poll_next(
457        mut self: std::pin::Pin<&mut Self>,
458        cx: &mut std::task::Context<'_>,
459    ) -> std::task::Poll<Option<Self::Item>> {
460        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
461            &mut self.event_receiver,
462            cx
463        )?) {
464            Some(buf) => std::task::Poll::Ready(Some(ChargerEvent::decode(buf))),
465            None => std::task::Poll::Ready(None),
466        }
467    }
468}
469
470#[derive(Debug)]
471pub enum ChargerEvent {
472    #[non_exhaustive]
473    _UnknownEvent {
474        /// Ordinal of the event that was sent.
475        ordinal: u64,
476    },
477}
478
479impl ChargerEvent {
480    /// Decodes a message buffer as a [`ChargerEvent`].
481    fn decode(
482        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
483    ) -> Result<ChargerEvent, fidl::Error> {
484        let (bytes, _handles) = buf.split_mut();
485        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
486        debug_assert_eq!(tx_header.tx_id, 0);
487        match tx_header.ordinal {
488            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
489                Ok(ChargerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
490            }
491            _ => Err(fidl::Error::UnknownOrdinal {
492                ordinal: tx_header.ordinal,
493                protocol_name: <ChargerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
494            }),
495        }
496    }
497}
498
499/// A Stream of incoming requests for fuchsia.hardware.power.charger/Charger.
500pub struct ChargerRequestStream {
501    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
502    is_terminated: bool,
503}
504
505impl std::marker::Unpin for ChargerRequestStream {}
506
507impl futures::stream::FusedStream for ChargerRequestStream {
508    fn is_terminated(&self) -> bool {
509        self.is_terminated
510    }
511}
512
513impl fidl::endpoints::RequestStream for ChargerRequestStream {
514    type Protocol = ChargerMarker;
515    type ControlHandle = ChargerControlHandle;
516
517    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
518        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
519    }
520
521    fn control_handle(&self) -> Self::ControlHandle {
522        ChargerControlHandle { inner: self.inner.clone() }
523    }
524
525    fn into_inner(
526        self,
527    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
528    {
529        (self.inner, self.is_terminated)
530    }
531
532    fn from_inner(
533        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
534        is_terminated: bool,
535    ) -> Self {
536        Self { inner, is_terminated }
537    }
538}
539
540impl futures::Stream for ChargerRequestStream {
541    type Item = Result<ChargerRequest, fidl::Error>;
542
543    fn poll_next(
544        mut self: std::pin::Pin<&mut Self>,
545        cx: &mut std::task::Context<'_>,
546    ) -> std::task::Poll<Option<Self::Item>> {
547        let this = &mut *self;
548        if this.inner.check_shutdown(cx) {
549            this.is_terminated = true;
550            return std::task::Poll::Ready(None);
551        }
552        if this.is_terminated {
553            panic!("polled ChargerRequestStream after completion");
554        }
555        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
556            |bytes, handles| {
557                match this.inner.channel().read_etc(cx, bytes, handles) {
558                    std::task::Poll::Ready(Ok(())) => {}
559                    std::task::Poll::Pending => return std::task::Poll::Pending,
560                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
561                        this.is_terminated = true;
562                        return std::task::Poll::Ready(None);
563                    }
564                    std::task::Poll::Ready(Err(e)) => {
565                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
566                            e.into(),
567                        ))));
568                    }
569                }
570
571                // A message has been received from the channel
572                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
573
574                std::task::Poll::Ready(Some(match header.ordinal {
575                    0x4f1a5fc6df415db3 => {
576                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
577                        let mut req = fidl::new_empty!(
578                            fidl::encoding::EmptyPayload,
579                            fidl::encoding::DefaultFuchsiaResourceDialect
580                        );
581                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
582                        let control_handle = ChargerControlHandle { inner: this.inner.clone() };
583                        Ok(ChargerRequest::GetSpec {
584                            responder: ChargerGetSpecResponder {
585                                control_handle: std::mem::ManuallyDrop::new(control_handle),
586                                tx_id: header.tx_id,
587                            },
588                        })
589                    }
590                    0x3c67651b7ec14d5e => {
591                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
592                        let mut req = fidl::new_empty!(
593                            fidl::encoding::EmptyPayload,
594                            fidl::encoding::DefaultFuchsiaResourceDialect
595                        );
596                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
597                        let control_handle = ChargerControlHandle { inner: this.inner.clone() };
598                        Ok(ChargerRequest::GetStatus {
599                            responder: ChargerGetStatusResponder {
600                                control_handle: std::mem::ManuallyDrop::new(control_handle),
601                                tx_id: header.tx_id,
602                            },
603                        })
604                    }
605                    0x282b21c4fe4452db => {
606                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
607                        let mut req = fidl::new_empty!(
608                            ChargerSetChargingEnabledRequest,
609                            fidl::encoding::DefaultFuchsiaResourceDialect
610                        );
611                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChargerSetChargingEnabledRequest>(&header, _body_bytes, handles, &mut req)?;
612                        let control_handle = ChargerControlHandle { inner: this.inner.clone() };
613                        Ok(ChargerRequest::SetChargingEnabled {
614                            enabled: req.enabled,
615
616                            responder: ChargerSetChargingEnabledResponder {
617                                control_handle: std::mem::ManuallyDrop::new(control_handle),
618                                tx_id: header.tx_id,
619                            },
620                        })
621                    }
622                    0x5a52d95d33d7c66e => {
623                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
624                        let mut req = fidl::new_empty!(
625                            ChargerWatchRequest,
626                            fidl::encoding::DefaultFuchsiaResourceDialect
627                        );
628                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChargerWatchRequest>(&header, _body_bytes, handles, &mut req)?;
629                        let control_handle = ChargerControlHandle { inner: this.inner.clone() };
630                        Ok(ChargerRequest::Watch {
631                            interest: req.interest,
632                            wake_on: req.wake_on,
633                            lease: req.lease,
634
635                            responder: ChargerWatchResponder {
636                                control_handle: std::mem::ManuallyDrop::new(control_handle),
637                                tx_id: header.tx_id,
638                            },
639                        })
640                    }
641                    _ if header.tx_id == 0
642                        && header
643                            .dynamic_flags()
644                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
645                    {
646                        Ok(ChargerRequest::_UnknownMethod {
647                            ordinal: header.ordinal,
648                            control_handle: ChargerControlHandle { inner: this.inner.clone() },
649                            method_type: fidl::MethodType::OneWay,
650                        })
651                    }
652                    _ if header
653                        .dynamic_flags()
654                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
655                    {
656                        this.inner.send_framework_err(
657                            fidl::encoding::FrameworkErr::UnknownMethod,
658                            header.tx_id,
659                            header.ordinal,
660                            header.dynamic_flags(),
661                            (bytes, handles),
662                        )?;
663                        Ok(ChargerRequest::_UnknownMethod {
664                            ordinal: header.ordinal,
665                            control_handle: ChargerControlHandle { inner: this.inner.clone() },
666                            method_type: fidl::MethodType::TwoWay,
667                        })
668                    }
669                    _ => Err(fidl::Error::UnknownOrdinal {
670                        ordinal: header.ordinal,
671                        protocol_name:
672                            <ChargerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
673                    }),
674                }))
675            },
676        )
677    }
678}
679
680#[derive(Debug)]
681pub enum ChargerRequest {
682    /// Returns static hardware characteristics of the charger.
683    GetSpec { responder: ChargerGetSpecResponder },
684    /// Returns the current dynamic status of the charger immediately.
685    GetStatus { responder: ChargerGetStatusResponder },
686    /// Control methods.
687    ///
688    /// Errors:
689    /// + `NOT_SUPPORTED`: If the hardware does not support enabling/disabling charging.
690    /// + `INTERNAL`: If an unexpected error occurred.
691    SetChargingEnabled { enabled: bool, responder: ChargerSetChargingEnabledResponder },
692    /// Change notification for charger state using a "hanging-get" pattern.
693    ///
694    /// Follows the same semantics and power management rules as
695    /// [`fuchsia.hardware.power.source/Source.Watch`].
696    ///
697    /// # Errors
698    ///
699    /// * `ALREADY_BOUND` if `Watch` is called before the previous call completes.
700    Watch {
701        interest: Status,
702        wake_on: Status,
703        lease: Option<fidl::EventPair>,
704        responder: ChargerWatchResponder,
705    },
706    /// An interaction was received which does not match any known method.
707    #[non_exhaustive]
708    _UnknownMethod {
709        /// Ordinal of the method that was called.
710        ordinal: u64,
711        control_handle: ChargerControlHandle,
712        method_type: fidl::MethodType,
713    },
714}
715
716impl ChargerRequest {
717    #[allow(irrefutable_let_patterns)]
718    pub fn into_get_spec(self) -> Option<(ChargerGetSpecResponder)> {
719        if let ChargerRequest::GetSpec { responder } = self { Some((responder)) } else { None }
720    }
721
722    #[allow(irrefutable_let_patterns)]
723    pub fn into_get_status(self) -> Option<(ChargerGetStatusResponder)> {
724        if let ChargerRequest::GetStatus { responder } = self { Some((responder)) } else { None }
725    }
726
727    #[allow(irrefutable_let_patterns)]
728    pub fn into_set_charging_enabled(self) -> Option<(bool, ChargerSetChargingEnabledResponder)> {
729        if let ChargerRequest::SetChargingEnabled { enabled, responder } = self {
730            Some((enabled, responder))
731        } else {
732            None
733        }
734    }
735
736    #[allow(irrefutable_let_patterns)]
737    pub fn into_watch(
738        self,
739    ) -> Option<(Status, Status, Option<fidl::EventPair>, ChargerWatchResponder)> {
740        if let ChargerRequest::Watch { interest, wake_on, lease, responder } = self {
741            Some((interest, wake_on, lease, responder))
742        } else {
743            None
744        }
745    }
746
747    /// Name of the method defined in FIDL
748    pub fn method_name(&self) -> &'static str {
749        match *self {
750            ChargerRequest::GetSpec { .. } => "get_spec",
751            ChargerRequest::GetStatus { .. } => "get_status",
752            ChargerRequest::SetChargingEnabled { .. } => "set_charging_enabled",
753            ChargerRequest::Watch { .. } => "watch",
754            ChargerRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
755                "unknown one-way method"
756            }
757            ChargerRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
758                "unknown two-way method"
759            }
760        }
761    }
762}
763
764#[derive(Debug, Clone)]
765pub struct ChargerControlHandle {
766    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
767}
768
769impl ChargerControlHandle {
770    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
771        self.inner.shutdown_with_epitaph(status.into())
772    }
773}
774
775impl fidl::endpoints::ControlHandle for ChargerControlHandle {
776    fn shutdown(&self) {
777        self.inner.shutdown()
778    }
779
780    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
781        self.inner.shutdown_with_epitaph(status)
782    }
783
784    fn is_closed(&self) -> bool {
785        self.inner.channel().is_closed()
786    }
787    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
788        self.inner.channel().on_closed()
789    }
790
791    #[cfg(target_os = "fuchsia")]
792    fn signal_peer(
793        &self,
794        clear_mask: zx::Signals,
795        set_mask: zx::Signals,
796    ) -> Result<(), zx_status::Status> {
797        use fidl::Peered;
798        self.inner.channel().signal_peer(clear_mask, set_mask)
799    }
800}
801
802impl ChargerControlHandle {}
803
804#[must_use = "FIDL methods require a response to be sent"]
805#[derive(Debug)]
806pub struct ChargerGetSpecResponder {
807    control_handle: std::mem::ManuallyDrop<ChargerControlHandle>,
808    tx_id: u32,
809}
810
811/// Set the the channel to be shutdown (see [`ChargerControlHandle::shutdown`])
812/// if the responder is dropped without sending a response, so that the client
813/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
814impl std::ops::Drop for ChargerGetSpecResponder {
815    fn drop(&mut self) {
816        self.control_handle.shutdown();
817        // Safety: drops once, never accessed again
818        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
819    }
820}
821
822impl fidl::endpoints::Responder for ChargerGetSpecResponder {
823    type ControlHandle = ChargerControlHandle;
824
825    fn control_handle(&self) -> &ChargerControlHandle {
826        &self.control_handle
827    }
828
829    fn drop_without_shutdown(mut self) {
830        // Safety: drops once, never accessed again due to mem::forget
831        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
832        // Prevent Drop from running (which would shut down the channel)
833        std::mem::forget(self);
834    }
835}
836
837impl ChargerGetSpecResponder {
838    /// Sends a response to the FIDL transaction.
839    ///
840    /// Sets the channel to shutdown if an error occurs.
841    pub fn send(
842        self,
843        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
844    ) -> Result<(), fidl::Error> {
845        let _result = self.send_raw(result);
846        if _result.is_err() {
847            self.control_handle.shutdown();
848        }
849        self.drop_without_shutdown();
850        _result
851    }
852
853    /// Similar to "send" but does not shutdown the channel if an error occurs.
854    pub fn send_no_shutdown_on_err(
855        self,
856        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
857    ) -> Result<(), fidl::Error> {
858        let _result = self.send_raw(result);
859        self.drop_without_shutdown();
860        _result
861    }
862
863    fn send_raw(
864        &self,
865        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
866    ) -> Result<(), fidl::Error> {
867        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
868            ChargerGetSpecResponse,
869            fidl_fuchsia_hardware_power_source::Error,
870        >>(
871            fidl::encoding::FlexibleResult::new(result.map(|spec| (spec,))),
872            self.tx_id,
873            0x4f1a5fc6df415db3,
874            fidl::encoding::DynamicFlags::FLEXIBLE,
875        )
876    }
877}
878
879#[must_use = "FIDL methods require a response to be sent"]
880#[derive(Debug)]
881pub struct ChargerGetStatusResponder {
882    control_handle: std::mem::ManuallyDrop<ChargerControlHandle>,
883    tx_id: u32,
884}
885
886/// Set the the channel to be shutdown (see [`ChargerControlHandle::shutdown`])
887/// if the responder is dropped without sending a response, so that the client
888/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
889impl std::ops::Drop for ChargerGetStatusResponder {
890    fn drop(&mut self) {
891        self.control_handle.shutdown();
892        // Safety: drops once, never accessed again
893        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
894    }
895}
896
897impl fidl::endpoints::Responder for ChargerGetStatusResponder {
898    type ControlHandle = ChargerControlHandle;
899
900    fn control_handle(&self) -> &ChargerControlHandle {
901        &self.control_handle
902    }
903
904    fn drop_without_shutdown(mut self) {
905        // Safety: drops once, never accessed again due to mem::forget
906        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
907        // Prevent Drop from running (which would shut down the channel)
908        std::mem::forget(self);
909    }
910}
911
912impl ChargerGetStatusResponder {
913    /// Sends a response to the FIDL transaction.
914    ///
915    /// Sets the channel to shutdown if an error occurs.
916    pub fn send(
917        self,
918        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
919    ) -> Result<(), fidl::Error> {
920        let _result = self.send_raw(result);
921        if _result.is_err() {
922            self.control_handle.shutdown();
923        }
924        self.drop_without_shutdown();
925        _result
926    }
927
928    /// Similar to "send" but does not shutdown the channel if an error occurs.
929    pub fn send_no_shutdown_on_err(
930        self,
931        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
932    ) -> Result<(), fidl::Error> {
933        let _result = self.send_raw(result);
934        self.drop_without_shutdown();
935        _result
936    }
937
938    fn send_raw(
939        &self,
940        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
941    ) -> Result<(), fidl::Error> {
942        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
943            ChargerGetStatusResponse,
944            fidl_fuchsia_hardware_power_source::Error,
945        >>(
946            fidl::encoding::FlexibleResult::new(result.map(|status| (status,))),
947            self.tx_id,
948            0x3c67651b7ec14d5e,
949            fidl::encoding::DynamicFlags::FLEXIBLE,
950        )
951    }
952}
953
954#[must_use = "FIDL methods require a response to be sent"]
955#[derive(Debug)]
956pub struct ChargerSetChargingEnabledResponder {
957    control_handle: std::mem::ManuallyDrop<ChargerControlHandle>,
958    tx_id: u32,
959}
960
961/// Set the the channel to be shutdown (see [`ChargerControlHandle::shutdown`])
962/// if the responder is dropped without sending a response, so that the client
963/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
964impl std::ops::Drop for ChargerSetChargingEnabledResponder {
965    fn drop(&mut self) {
966        self.control_handle.shutdown();
967        // Safety: drops once, never accessed again
968        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
969    }
970}
971
972impl fidl::endpoints::Responder for ChargerSetChargingEnabledResponder {
973    type ControlHandle = ChargerControlHandle;
974
975    fn control_handle(&self) -> &ChargerControlHandle {
976        &self.control_handle
977    }
978
979    fn drop_without_shutdown(mut self) {
980        // Safety: drops once, never accessed again due to mem::forget
981        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
982        // Prevent Drop from running (which would shut down the channel)
983        std::mem::forget(self);
984    }
985}
986
987impl ChargerSetChargingEnabledResponder {
988    /// Sends a response to the FIDL transaction.
989    ///
990    /// Sets the channel to shutdown if an error occurs.
991    pub fn send(
992        self,
993        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
994    ) -> Result<(), fidl::Error> {
995        let _result = self.send_raw(result);
996        if _result.is_err() {
997            self.control_handle.shutdown();
998        }
999        self.drop_without_shutdown();
1000        _result
1001    }
1002
1003    /// Similar to "send" but does not shutdown the channel if an error occurs.
1004    pub fn send_no_shutdown_on_err(
1005        self,
1006        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
1007    ) -> Result<(), fidl::Error> {
1008        let _result = self.send_raw(result);
1009        self.drop_without_shutdown();
1010        _result
1011    }
1012
1013    fn send_raw(
1014        &self,
1015        mut result: Result<(), fidl_fuchsia_hardware_power_source::Error>,
1016    ) -> Result<(), fidl::Error> {
1017        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1018            fidl::encoding::EmptyStruct,
1019            fidl_fuchsia_hardware_power_source::Error,
1020        >>(
1021            fidl::encoding::FlexibleResult::new(result),
1022            self.tx_id,
1023            0x282b21c4fe4452db,
1024            fidl::encoding::DynamicFlags::FLEXIBLE,
1025        )
1026    }
1027}
1028
1029#[must_use = "FIDL methods require a response to be sent"]
1030#[derive(Debug)]
1031pub struct ChargerWatchResponder {
1032    control_handle: std::mem::ManuallyDrop<ChargerControlHandle>,
1033    tx_id: u32,
1034}
1035
1036/// Set the the channel to be shutdown (see [`ChargerControlHandle::shutdown`])
1037/// if the responder is dropped without sending a response, so that the client
1038/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1039impl std::ops::Drop for ChargerWatchResponder {
1040    fn drop(&mut self) {
1041        self.control_handle.shutdown();
1042        // Safety: drops once, never accessed again
1043        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1044    }
1045}
1046
1047impl fidl::endpoints::Responder for ChargerWatchResponder {
1048    type ControlHandle = ChargerControlHandle;
1049
1050    fn control_handle(&self) -> &ChargerControlHandle {
1051        &self.control_handle
1052    }
1053
1054    fn drop_without_shutdown(mut self) {
1055        // Safety: drops once, never accessed again due to mem::forget
1056        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1057        // Prevent Drop from running (which would shut down the channel)
1058        std::mem::forget(self);
1059    }
1060}
1061
1062impl ChargerWatchResponder {
1063    /// Sends a response to the FIDL transaction.
1064    ///
1065    /// Sets the channel to shutdown if an error occurs.
1066    pub fn send(
1067        self,
1068        mut result: Result<
1069            (&Status, Option<fidl::EventPair>),
1070            fidl_fuchsia_hardware_power_source::Error,
1071        >,
1072    ) -> Result<(), fidl::Error> {
1073        let _result = self.send_raw(result);
1074        if _result.is_err() {
1075            self.control_handle.shutdown();
1076        }
1077        self.drop_without_shutdown();
1078        _result
1079    }
1080
1081    /// Similar to "send" but does not shutdown the channel if an error occurs.
1082    pub fn send_no_shutdown_on_err(
1083        self,
1084        mut result: Result<
1085            (&Status, Option<fidl::EventPair>),
1086            fidl_fuchsia_hardware_power_source::Error,
1087        >,
1088    ) -> Result<(), fidl::Error> {
1089        let _result = self.send_raw(result);
1090        self.drop_without_shutdown();
1091        _result
1092    }
1093
1094    fn send_raw(
1095        &self,
1096        mut result: Result<
1097            (&Status, Option<fidl::EventPair>),
1098            fidl_fuchsia_hardware_power_source::Error,
1099        >,
1100    ) -> Result<(), fidl::Error> {
1101        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1102            ChargerWatchResponse,
1103            fidl_fuchsia_hardware_power_source::Error,
1104        >>(
1105            fidl::encoding::FlexibleResult::new(result),
1106            self.tx_id,
1107            0x5a52d95d33d7c66e,
1108            fidl::encoding::DynamicFlags::FLEXIBLE,
1109        )
1110    }
1111}
1112
1113#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1114pub struct ServiceMarker;
1115
1116#[cfg(target_os = "fuchsia")]
1117impl fidl::endpoints::ServiceMarker for ServiceMarker {
1118    type Proxy = ServiceProxy;
1119    type Request = ServiceRequest;
1120    const SERVICE_NAME: &'static str = "fuchsia.hardware.power.charger.Service";
1121}
1122
1123/// A request for one of the member protocols of Service.
1124///
1125#[cfg(target_os = "fuchsia")]
1126pub enum ServiceRequest {
1127    Charger(ChargerRequestStream),
1128    PowerSource(fidl_fuchsia_hardware_power_source::SourceRequestStream),
1129}
1130
1131#[cfg(target_os = "fuchsia")]
1132impl fidl::endpoints::ServiceRequest for ServiceRequest {
1133    type Service = ServiceMarker;
1134
1135    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1136        match name {
1137            "charger" => Self::Charger(
1138                <ChargerRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1139            ),
1140            "power_source" => Self::PowerSource(
1141                <fidl_fuchsia_hardware_power_source::SourceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1142            ),
1143            _ => panic!("no such member protocol name for service Service"),
1144        }
1145    }
1146
1147    fn member_names() -> &'static [&'static str] {
1148        &["charger", "power_source"]
1149    }
1150}
1151#[cfg(target_os = "fuchsia")]
1152pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1153
1154#[cfg(target_os = "fuchsia")]
1155impl fidl::endpoints::ServiceProxy for ServiceProxy {
1156    type Service = ServiceMarker;
1157
1158    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1159        Self(opener)
1160    }
1161}
1162
1163#[cfg(target_os = "fuchsia")]
1164impl ServiceProxy {
1165    pub fn connect_to_charger(&self) -> Result<ChargerProxy, fidl::Error> {
1166        let (proxy, server_end) = fidl::endpoints::create_proxy::<ChargerMarker>();
1167        self.connect_channel_to_charger(server_end)?;
1168        Ok(proxy)
1169    }
1170
1171    /// Like `connect_to_charger`, but returns a sync proxy.
1172    /// See [`Self::connect_to_charger`] for more details.
1173    pub fn connect_to_charger_sync(&self) -> Result<ChargerSynchronousProxy, fidl::Error> {
1174        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<ChargerMarker>();
1175        self.connect_channel_to_charger(server_end)?;
1176        Ok(proxy)
1177    }
1178
1179    /// Like `connect_to_charger`, but accepts a server end.
1180    /// See [`Self::connect_to_charger`] for more details.
1181    pub fn connect_channel_to_charger(
1182        &self,
1183        server_end: fidl::endpoints::ServerEnd<ChargerMarker>,
1184    ) -> Result<(), fidl::Error> {
1185        self.0.open_member("charger", server_end.into_channel())
1186    }
1187    pub fn connect_to_power_source(
1188        &self,
1189    ) -> Result<fidl_fuchsia_hardware_power_source::SourceProxy, fidl::Error> {
1190        let (proxy, server_end) =
1191            fidl::endpoints::create_proxy::<fidl_fuchsia_hardware_power_source::SourceMarker>();
1192        self.connect_channel_to_power_source(server_end)?;
1193        Ok(proxy)
1194    }
1195
1196    /// Like `connect_to_power_source`, but returns a sync proxy.
1197    /// See [`Self::connect_to_power_source`] for more details.
1198    pub fn connect_to_power_source_sync(
1199        &self,
1200    ) -> Result<fidl_fuchsia_hardware_power_source::SourceSynchronousProxy, fidl::Error> {
1201        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<
1202            fidl_fuchsia_hardware_power_source::SourceMarker,
1203        >();
1204        self.connect_channel_to_power_source(server_end)?;
1205        Ok(proxy)
1206    }
1207
1208    /// Like `connect_to_power_source`, but accepts a server end.
1209    /// See [`Self::connect_to_power_source`] for more details.
1210    pub fn connect_channel_to_power_source(
1211        &self,
1212        server_end: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_power_source::SourceMarker>,
1213    ) -> Result<(), fidl::Error> {
1214        self.0.open_member("power_source", server_end.into_channel())
1215    }
1216
1217    pub fn instance_name(&self) -> &str {
1218        self.0.instance_name()
1219    }
1220}
1221
1222mod internal {
1223    use super::*;
1224
1225    impl fidl::encoding::ResourceTypeMarker for ChargerWatchRequest {
1226        type Borrowed<'a> = &'a mut Self;
1227        fn take_or_borrow<'a>(
1228            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1229        ) -> Self::Borrowed<'a> {
1230            value
1231        }
1232    }
1233
1234    unsafe impl fidl::encoding::TypeMarker for ChargerWatchRequest {
1235        type Owned = Self;
1236
1237        #[inline(always)]
1238        fn inline_align(_context: fidl::encoding::Context) -> usize {
1239            8
1240        }
1241
1242        #[inline(always)]
1243        fn inline_size(_context: fidl::encoding::Context) -> usize {
1244            40
1245        }
1246    }
1247
1248    unsafe impl
1249        fidl::encoding::Encode<ChargerWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1250        for &mut ChargerWatchRequest
1251    {
1252        #[inline]
1253        unsafe fn encode(
1254            self,
1255            encoder: &mut fidl::encoding::Encoder<
1256                '_,
1257                fidl::encoding::DefaultFuchsiaResourceDialect,
1258            >,
1259            offset: usize,
1260            _depth: fidl::encoding::Depth,
1261        ) -> fidl::Result<()> {
1262            encoder.debug_check_bounds::<ChargerWatchRequest>(offset);
1263            // Delegate to tuple encoding.
1264            fidl::encoding::Encode::<
1265                ChargerWatchRequest,
1266                fidl::encoding::DefaultFuchsiaResourceDialect,
1267            >::encode(
1268                (
1269                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.interest),
1270                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.wake_on),
1271                    <fidl::encoding::Optional<
1272                        fidl::encoding::HandleType<
1273                            fidl::EventPair,
1274                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1275                            16387,
1276                        >,
1277                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1278                        &mut self.lease
1279                    ),
1280                ),
1281                encoder,
1282                offset,
1283                _depth,
1284            )
1285        }
1286    }
1287    unsafe impl<
1288        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1289        T1: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1290        T2: fidl::encoding::Encode<
1291                fidl::encoding::Optional<
1292                    fidl::encoding::HandleType<
1293                        fidl::EventPair,
1294                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1295                        16387,
1296                    >,
1297                >,
1298                fidl::encoding::DefaultFuchsiaResourceDialect,
1299            >,
1300    > fidl::encoding::Encode<ChargerWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1301        for (T0, T1, T2)
1302    {
1303        #[inline]
1304        unsafe fn encode(
1305            self,
1306            encoder: &mut fidl::encoding::Encoder<
1307                '_,
1308                fidl::encoding::DefaultFuchsiaResourceDialect,
1309            >,
1310            offset: usize,
1311            depth: fidl::encoding::Depth,
1312        ) -> fidl::Result<()> {
1313            encoder.debug_check_bounds::<ChargerWatchRequest>(offset);
1314            // Zero out padding regions. There's no need to apply masks
1315            // because the unmasked parts will be overwritten by fields.
1316            unsafe {
1317                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
1318                (ptr as *mut u64).write_unaligned(0);
1319            }
1320            // Write the fields.
1321            self.0.encode(encoder, offset + 0, depth)?;
1322            self.1.encode(encoder, offset + 16, depth)?;
1323            self.2.encode(encoder, offset + 32, depth)?;
1324            Ok(())
1325        }
1326    }
1327
1328    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1329        for ChargerWatchRequest
1330    {
1331        #[inline(always)]
1332        fn new_empty() -> Self {
1333            Self {
1334                interest: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1335                wake_on: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1336                lease: fidl::new_empty!(
1337                    fidl::encoding::Optional<
1338                        fidl::encoding::HandleType<
1339                            fidl::EventPair,
1340                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1341                            16387,
1342                        >,
1343                    >,
1344                    fidl::encoding::DefaultFuchsiaResourceDialect
1345                ),
1346            }
1347        }
1348
1349        #[inline]
1350        unsafe fn decode(
1351            &mut self,
1352            decoder: &mut fidl::encoding::Decoder<
1353                '_,
1354                fidl::encoding::DefaultFuchsiaResourceDialect,
1355            >,
1356            offset: usize,
1357            _depth: fidl::encoding::Depth,
1358        ) -> fidl::Result<()> {
1359            decoder.debug_check_bounds::<Self>(offset);
1360            // Verify that padding bytes are zero.
1361            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
1362            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1363            let mask = 0xffffffff00000000u64;
1364            let maskedval = padval & mask;
1365            if maskedval != 0 {
1366                return Err(fidl::Error::NonZeroPadding {
1367                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
1368                });
1369            }
1370            fidl::decode!(
1371                Status,
1372                fidl::encoding::DefaultFuchsiaResourceDialect,
1373                &mut self.interest,
1374                decoder,
1375                offset + 0,
1376                _depth
1377            )?;
1378            fidl::decode!(
1379                Status,
1380                fidl::encoding::DefaultFuchsiaResourceDialect,
1381                &mut self.wake_on,
1382                decoder,
1383                offset + 16,
1384                _depth
1385            )?;
1386            fidl::decode!(
1387                fidl::encoding::Optional<
1388                    fidl::encoding::HandleType<
1389                        fidl::EventPair,
1390                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1391                        16387,
1392                    >,
1393                >,
1394                fidl::encoding::DefaultFuchsiaResourceDialect,
1395                &mut self.lease,
1396                decoder,
1397                offset + 32,
1398                _depth
1399            )?;
1400            Ok(())
1401        }
1402    }
1403
1404    impl fidl::encoding::ResourceTypeMarker for ChargerWatchResponse {
1405        type Borrowed<'a> = &'a mut Self;
1406        fn take_or_borrow<'a>(
1407            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1408        ) -> Self::Borrowed<'a> {
1409            value
1410        }
1411    }
1412
1413    unsafe impl fidl::encoding::TypeMarker for ChargerWatchResponse {
1414        type Owned = Self;
1415
1416        #[inline(always)]
1417        fn inline_align(_context: fidl::encoding::Context) -> usize {
1418            8
1419        }
1420
1421        #[inline(always)]
1422        fn inline_size(_context: fidl::encoding::Context) -> usize {
1423            24
1424        }
1425    }
1426
1427    unsafe impl
1428        fidl::encoding::Encode<ChargerWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1429        for &mut ChargerWatchResponse
1430    {
1431        #[inline]
1432        unsafe fn encode(
1433            self,
1434            encoder: &mut fidl::encoding::Encoder<
1435                '_,
1436                fidl::encoding::DefaultFuchsiaResourceDialect,
1437            >,
1438            offset: usize,
1439            _depth: fidl::encoding::Depth,
1440        ) -> fidl::Result<()> {
1441            encoder.debug_check_bounds::<ChargerWatchResponse>(offset);
1442            // Delegate to tuple encoding.
1443            fidl::encoding::Encode::<
1444                ChargerWatchResponse,
1445                fidl::encoding::DefaultFuchsiaResourceDialect,
1446            >::encode(
1447                (
1448                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
1449                    <fidl::encoding::Optional<
1450                        fidl::encoding::HandleType<
1451                            fidl::EventPair,
1452                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1453                            16387,
1454                        >,
1455                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1456                        &mut self.wake_lease
1457                    ),
1458                ),
1459                encoder,
1460                offset,
1461                _depth,
1462            )
1463        }
1464    }
1465    unsafe impl<
1466        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1467        T1: fidl::encoding::Encode<
1468                fidl::encoding::Optional<
1469                    fidl::encoding::HandleType<
1470                        fidl::EventPair,
1471                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1472                        16387,
1473                    >,
1474                >,
1475                fidl::encoding::DefaultFuchsiaResourceDialect,
1476            >,
1477    >
1478        fidl::encoding::Encode<ChargerWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1479        for (T0, T1)
1480    {
1481        #[inline]
1482        unsafe fn encode(
1483            self,
1484            encoder: &mut fidl::encoding::Encoder<
1485                '_,
1486                fidl::encoding::DefaultFuchsiaResourceDialect,
1487            >,
1488            offset: usize,
1489            depth: fidl::encoding::Depth,
1490        ) -> fidl::Result<()> {
1491            encoder.debug_check_bounds::<ChargerWatchResponse>(offset);
1492            // Zero out padding regions. There's no need to apply masks
1493            // because the unmasked parts will be overwritten by fields.
1494            unsafe {
1495                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1496                (ptr as *mut u64).write_unaligned(0);
1497            }
1498            // Write the fields.
1499            self.0.encode(encoder, offset + 0, depth)?;
1500            self.1.encode(encoder, offset + 16, depth)?;
1501            Ok(())
1502        }
1503    }
1504
1505    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1506        for ChargerWatchResponse
1507    {
1508        #[inline(always)]
1509        fn new_empty() -> Self {
1510            Self {
1511                status: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1512                wake_lease: fidl::new_empty!(
1513                    fidl::encoding::Optional<
1514                        fidl::encoding::HandleType<
1515                            fidl::EventPair,
1516                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1517                            16387,
1518                        >,
1519                    >,
1520                    fidl::encoding::DefaultFuchsiaResourceDialect
1521                ),
1522            }
1523        }
1524
1525        #[inline]
1526        unsafe fn decode(
1527            &mut self,
1528            decoder: &mut fidl::encoding::Decoder<
1529                '_,
1530                fidl::encoding::DefaultFuchsiaResourceDialect,
1531            >,
1532            offset: usize,
1533            _depth: fidl::encoding::Depth,
1534        ) -> fidl::Result<()> {
1535            decoder.debug_check_bounds::<Self>(offset);
1536            // Verify that padding bytes are zero.
1537            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1538            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1539            let mask = 0xffffffff00000000u64;
1540            let maskedval = padval & mask;
1541            if maskedval != 0 {
1542                return Err(fidl::Error::NonZeroPadding {
1543                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1544                });
1545            }
1546            fidl::decode!(
1547                Status,
1548                fidl::encoding::DefaultFuchsiaResourceDialect,
1549                &mut self.status,
1550                decoder,
1551                offset + 0,
1552                _depth
1553            )?;
1554            fidl::decode!(
1555                fidl::encoding::Optional<
1556                    fidl::encoding::HandleType<
1557                        fidl::EventPair,
1558                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1559                        16387,
1560                    >,
1561                >,
1562                fidl::encoding::DefaultFuchsiaResourceDialect,
1563                &mut self.wake_lease,
1564                decoder,
1565                offset + 16,
1566                _depth
1567            )?;
1568            Ok(())
1569        }
1570    }
1571}