Skip to main content

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