fidl_fuchsia_power_profile__common/
fidl_fuchsia_power_profile__common.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::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// System power profiles that may be returned by [Watcher.Watch].
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[repr(u32)]
14pub enum Profile {
15    /// There is no active work in the system. On a system that supports it, the device may be put
16    /// into a lower-power or suspended state at any time.
17    Idle = 1,
18    /// Some background activity is occurring that should prevent the system from dropping into a
19    /// non-running or suspended state (example: downloading an OTA, performing a backup, or
20    /// CPU-based hotword monitoring).
21    BackgroundActive = 2,
22    /// The device is providing some user-visible experience such as running an app in the
23    /// foreground or streaming audio, or has recently received interaction from a user.
24    UserActive = 3,
25}
26
27impl Profile {
28    #[inline]
29    pub fn from_primitive(prim: u32) -> Option<Self> {
30        match prim {
31            1 => Some(Self::Idle),
32            2 => Some(Self::BackgroundActive),
33            3 => Some(Self::UserActive),
34            _ => None,
35        }
36    }
37
38    #[inline]
39    pub const fn into_primitive(self) -> u32 {
40        self as u32
41    }
42}
43
44#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
45pub struct WatcherWatchResponse {
46    pub profile: Profile,
47}
48
49impl fidl::Persistable for WatcherWatchResponse {}
50
51mod internal {
52    use super::*;
53    unsafe impl fidl::encoding::TypeMarker for Profile {
54        type Owned = Self;
55
56        #[inline(always)]
57        fn inline_align(_context: fidl::encoding::Context) -> usize {
58            std::mem::align_of::<u32>()
59        }
60
61        #[inline(always)]
62        fn inline_size(_context: fidl::encoding::Context) -> usize {
63            std::mem::size_of::<u32>()
64        }
65
66        #[inline(always)]
67        fn encode_is_copy() -> bool {
68            true
69        }
70
71        #[inline(always)]
72        fn decode_is_copy() -> bool {
73            false
74        }
75    }
76
77    impl fidl::encoding::ValueTypeMarker for Profile {
78        type Borrowed<'a> = Self;
79        #[inline(always)]
80        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
81            *value
82        }
83    }
84
85    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Profile {
86        #[inline]
87        unsafe fn encode(
88            self,
89            encoder: &mut fidl::encoding::Encoder<'_, D>,
90            offset: usize,
91            _depth: fidl::encoding::Depth,
92        ) -> fidl::Result<()> {
93            encoder.debug_check_bounds::<Self>(offset);
94            encoder.write_num(self.into_primitive(), offset);
95            Ok(())
96        }
97    }
98
99    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Profile {
100        #[inline(always)]
101        fn new_empty() -> Self {
102            Self::Idle
103        }
104
105        #[inline]
106        unsafe fn decode(
107            &mut self,
108            decoder: &mut fidl::encoding::Decoder<'_, D>,
109            offset: usize,
110            _depth: fidl::encoding::Depth,
111        ) -> fidl::Result<()> {
112            decoder.debug_check_bounds::<Self>(offset);
113            let prim = decoder.read_num::<u32>(offset);
114
115            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
116            Ok(())
117        }
118    }
119
120    impl fidl::encoding::ValueTypeMarker for WatcherWatchResponse {
121        type Borrowed<'a> = &'a Self;
122        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
123            value
124        }
125    }
126
127    unsafe impl fidl::encoding::TypeMarker for WatcherWatchResponse {
128        type Owned = Self;
129
130        #[inline(always)]
131        fn inline_align(_context: fidl::encoding::Context) -> usize {
132            4
133        }
134
135        #[inline(always)]
136        fn inline_size(_context: fidl::encoding::Context) -> usize {
137            4
138        }
139    }
140
141    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatcherWatchResponse, D>
142        for &WatcherWatchResponse
143    {
144        #[inline]
145        unsafe fn encode(
146            self,
147            encoder: &mut fidl::encoding::Encoder<'_, D>,
148            offset: usize,
149            _depth: fidl::encoding::Depth,
150        ) -> fidl::Result<()> {
151            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
152            // Delegate to tuple encoding.
153            fidl::encoding::Encode::<WatcherWatchResponse, D>::encode(
154                (<Profile as fidl::encoding::ValueTypeMarker>::borrow(&self.profile),),
155                encoder,
156                offset,
157                _depth,
158            )
159        }
160    }
161    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Profile, D>>
162        fidl::encoding::Encode<WatcherWatchResponse, D> for (T0,)
163    {
164        #[inline]
165        unsafe fn encode(
166            self,
167            encoder: &mut fidl::encoding::Encoder<'_, D>,
168            offset: usize,
169            depth: fidl::encoding::Depth,
170        ) -> fidl::Result<()> {
171            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
172            // Zero out padding regions. There's no need to apply masks
173            // because the unmasked parts will be overwritten by fields.
174            // Write the fields.
175            self.0.encode(encoder, offset + 0, depth)?;
176            Ok(())
177        }
178    }
179
180    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatcherWatchResponse {
181        #[inline(always)]
182        fn new_empty() -> Self {
183            Self { profile: fidl::new_empty!(Profile, D) }
184        }
185
186        #[inline]
187        unsafe fn decode(
188            &mut self,
189            decoder: &mut fidl::encoding::Decoder<'_, D>,
190            offset: usize,
191            _depth: fidl::encoding::Depth,
192        ) -> fidl::Result<()> {
193            decoder.debug_check_bounds::<Self>(offset);
194            // Verify that padding bytes are zero.
195            fidl::decode!(Profile, D, &mut self.profile, decoder, offset + 0, _depth)?;
196            Ok(())
197        }
198    }
199}