fidl_fuchsia_system_state_common/
fidl_fuchsia_system_state_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/// The number of variants of `SystemPowerState`.
12pub const MAX_SYSTEM_POWER_STATES: u32 = 8;
13
14#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
15#[repr(u8)]
16pub enum SystemPowerState {
17    FullyOn = 1,
18    Reboot = 2,
19    RebootBootloader = 3,
20    RebootRecovery = 4,
21    Poweroff = 5,
22    Mexec = 6,
23    SuspendRam = 7,
24    RebootKernelInitiated = 8,
25}
26
27impl SystemPowerState {
28    #[inline]
29    pub fn from_primitive(prim: u8) -> Option<Self> {
30        match prim {
31            1 => Some(Self::FullyOn),
32            2 => Some(Self::Reboot),
33            3 => Some(Self::RebootBootloader),
34            4 => Some(Self::RebootRecovery),
35            5 => Some(Self::Poweroff),
36            6 => Some(Self::Mexec),
37            7 => Some(Self::SuspendRam),
38            8 => Some(Self::RebootKernelInitiated),
39            _ => None,
40        }
41    }
42
43    #[inline]
44    pub const fn into_primitive(self) -> u8 {
45        self as u8
46    }
47
48    #[deprecated = "Strict enums should not use `is_unknown`"]
49    #[inline]
50    pub fn is_unknown(&self) -> bool {
51        false
52    }
53}
54
55#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
56pub struct SystemStateTransitionGetTerminationSystemStateResponse {
57    pub state: SystemPowerState,
58}
59
60impl fidl::Persistable for SystemStateTransitionGetTerminationSystemStateResponse {}
61
62mod internal {
63    use super::*;
64    unsafe impl fidl::encoding::TypeMarker for SystemPowerState {
65        type Owned = Self;
66
67        #[inline(always)]
68        fn inline_align(_context: fidl::encoding::Context) -> usize {
69            std::mem::align_of::<u8>()
70        }
71
72        #[inline(always)]
73        fn inline_size(_context: fidl::encoding::Context) -> usize {
74            std::mem::size_of::<u8>()
75        }
76
77        #[inline(always)]
78        fn encode_is_copy() -> bool {
79            true
80        }
81
82        #[inline(always)]
83        fn decode_is_copy() -> bool {
84            false
85        }
86    }
87
88    impl fidl::encoding::ValueTypeMarker for SystemPowerState {
89        type Borrowed<'a> = Self;
90        #[inline(always)]
91        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
92            *value
93        }
94    }
95
96    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
97        for SystemPowerState
98    {
99        #[inline]
100        unsafe fn encode(
101            self,
102            encoder: &mut fidl::encoding::Encoder<'_, D>,
103            offset: usize,
104            _depth: fidl::encoding::Depth,
105        ) -> fidl::Result<()> {
106            encoder.debug_check_bounds::<Self>(offset);
107            encoder.write_num(self.into_primitive(), offset);
108            Ok(())
109        }
110    }
111
112    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SystemPowerState {
113        #[inline(always)]
114        fn new_empty() -> Self {
115            Self::FullyOn
116        }
117
118        #[inline]
119        unsafe fn decode(
120            &mut self,
121            decoder: &mut fidl::encoding::Decoder<'_, D>,
122            offset: usize,
123            _depth: fidl::encoding::Depth,
124        ) -> fidl::Result<()> {
125            decoder.debug_check_bounds::<Self>(offset);
126            let prim = decoder.read_num::<u8>(offset);
127
128            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
129            Ok(())
130        }
131    }
132
133    impl fidl::encoding::ValueTypeMarker for SystemStateTransitionGetTerminationSystemStateResponse {
134        type Borrowed<'a> = &'a Self;
135        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
136            value
137        }
138    }
139
140    unsafe impl fidl::encoding::TypeMarker for SystemStateTransitionGetTerminationSystemStateResponse {
141        type Owned = Self;
142
143        #[inline(always)]
144        fn inline_align(_context: fidl::encoding::Context) -> usize {
145            1
146        }
147
148        #[inline(always)]
149        fn inline_size(_context: fidl::encoding::Context) -> usize {
150            1
151        }
152    }
153
154    unsafe impl<D: fidl::encoding::ResourceDialect>
155        fidl::encoding::Encode<SystemStateTransitionGetTerminationSystemStateResponse, D>
156        for &SystemStateTransitionGetTerminationSystemStateResponse
157    {
158        #[inline]
159        unsafe fn encode(
160            self,
161            encoder: &mut fidl::encoding::Encoder<'_, D>,
162            offset: usize,
163            _depth: fidl::encoding::Depth,
164        ) -> fidl::Result<()> {
165            encoder.debug_check_bounds::<SystemStateTransitionGetTerminationSystemStateResponse>(
166                offset,
167            );
168            // Delegate to tuple encoding.
169            fidl::encoding::Encode::<SystemStateTransitionGetTerminationSystemStateResponse, D>::encode(
170                (
171                    <SystemPowerState as fidl::encoding::ValueTypeMarker>::borrow(&self.state),
172                ),
173                encoder, offset, _depth
174            )
175        }
176    }
177    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<SystemPowerState, D>>
178        fidl::encoding::Encode<SystemStateTransitionGetTerminationSystemStateResponse, D> for (T0,)
179    {
180        #[inline]
181        unsafe fn encode(
182            self,
183            encoder: &mut fidl::encoding::Encoder<'_, D>,
184            offset: usize,
185            depth: fidl::encoding::Depth,
186        ) -> fidl::Result<()> {
187            encoder.debug_check_bounds::<SystemStateTransitionGetTerminationSystemStateResponse>(
188                offset,
189            );
190            // Zero out padding regions. There's no need to apply masks
191            // because the unmasked parts will be overwritten by fields.
192            // Write the fields.
193            self.0.encode(encoder, offset + 0, depth)?;
194            Ok(())
195        }
196    }
197
198    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
199        for SystemStateTransitionGetTerminationSystemStateResponse
200    {
201        #[inline(always)]
202        fn new_empty() -> Self {
203            Self { state: fidl::new_empty!(SystemPowerState, D) }
204        }
205
206        #[inline]
207        unsafe fn decode(
208            &mut self,
209            decoder: &mut fidl::encoding::Decoder<'_, D>,
210            offset: usize,
211            _depth: fidl::encoding::Depth,
212        ) -> fidl::Result<()> {
213            decoder.debug_check_bounds::<Self>(offset);
214            // Verify that padding bytes are zero.
215            fidl::decode!(SystemPowerState, D, &mut self.state, decoder, offset + 0, _depth)?;
216            Ok(())
217        }
218    }
219}