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