fidl_fuchsia_session_power_common/
fidl_fuchsia_session_power_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/// Error when taking the power lease.
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13pub enum HandoffError {
14    /// The lease is already taken.
15    AlreadyTaken,
16    /// The lease is not available due to errors or configuration.
17    Unavailable,
18    #[doc(hidden)]
19    __SourceBreaking { unknown_ordinal: u32 },
20}
21
22/// Pattern that matches an unknown `HandoffError` member.
23#[macro_export]
24macro_rules! HandoffErrorUnknown {
25    () => {
26        _
27    };
28}
29
30impl HandoffError {
31    #[inline]
32    pub fn from_primitive(prim: u32) -> Option<Self> {
33        match prim {
34            1 => Some(Self::AlreadyTaken),
35            2 => Some(Self::Unavailable),
36            _ => None,
37        }
38    }
39
40    #[inline]
41    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
42        match prim {
43            1 => Self::AlreadyTaken,
44            2 => Self::Unavailable,
45            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
46        }
47    }
48
49    #[inline]
50    pub fn unknown() -> Self {
51        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
52    }
53
54    #[inline]
55    pub const fn into_primitive(self) -> u32 {
56        match self {
57            Self::AlreadyTaken => 1,
58            Self::Unavailable => 2,
59            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
60        }
61    }
62
63    #[inline]
64    pub fn is_unknown(&self) -> bool {
65        match self {
66            Self::__SourceBreaking { unknown_ordinal: _ } => true,
67            _ => false,
68        }
69    }
70}
71
72mod internal {
73    use super::*;
74    unsafe impl fidl::encoding::TypeMarker for HandoffError {
75        type Owned = Self;
76
77        #[inline(always)]
78        fn inline_align(_context: fidl::encoding::Context) -> usize {
79            std::mem::align_of::<u32>()
80        }
81
82        #[inline(always)]
83        fn inline_size(_context: fidl::encoding::Context) -> usize {
84            std::mem::size_of::<u32>()
85        }
86
87        #[inline(always)]
88        fn encode_is_copy() -> bool {
89            false
90        }
91
92        #[inline(always)]
93        fn decode_is_copy() -> bool {
94            false
95        }
96    }
97
98    impl fidl::encoding::ValueTypeMarker for HandoffError {
99        type Borrowed<'a> = Self;
100        #[inline(always)]
101        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
102            *value
103        }
104    }
105
106    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for HandoffError {
107        #[inline]
108        unsafe fn encode(
109            self,
110            encoder: &mut fidl::encoding::Encoder<'_, D>,
111            offset: usize,
112            _depth: fidl::encoding::Depth,
113        ) -> fidl::Result<()> {
114            encoder.debug_check_bounds::<Self>(offset);
115            encoder.write_num(self.into_primitive(), offset);
116            Ok(())
117        }
118    }
119
120    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for HandoffError {
121        #[inline(always)]
122        fn new_empty() -> Self {
123            Self::unknown()
124        }
125
126        #[inline]
127        unsafe fn decode(
128            &mut self,
129            decoder: &mut fidl::encoding::Decoder<'_, D>,
130            offset: usize,
131            _depth: fidl::encoding::Depth,
132        ) -> fidl::Result<()> {
133            decoder.debug_check_bounds::<Self>(offset);
134            let prim = decoder.read_num::<u32>(offset);
135
136            *self = Self::from_primitive_allow_unknown(prim);
137            Ok(())
138        }
139    }
140}