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
72pub mod handoff_ordinals {
73    pub const TAKE: u64 = 0x7150089bdc73770b;
74}
75
76mod internal {
77    use super::*;
78    unsafe impl fidl::encoding::TypeMarker for HandoffError {
79        type Owned = Self;
80
81        #[inline(always)]
82        fn inline_align(_context: fidl::encoding::Context) -> usize {
83            std::mem::align_of::<u32>()
84        }
85
86        #[inline(always)]
87        fn inline_size(_context: fidl::encoding::Context) -> usize {
88            std::mem::size_of::<u32>()
89        }
90
91        #[inline(always)]
92        fn encode_is_copy() -> bool {
93            false
94        }
95
96        #[inline(always)]
97        fn decode_is_copy() -> bool {
98            false
99        }
100    }
101
102    impl fidl::encoding::ValueTypeMarker for HandoffError {
103        type Borrowed<'a> = Self;
104        #[inline(always)]
105        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
106            *value
107        }
108    }
109
110    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for HandoffError {
111        #[inline]
112        unsafe fn encode(
113            self,
114            encoder: &mut fidl::encoding::Encoder<'_, D>,
115            offset: usize,
116            _depth: fidl::encoding::Depth,
117        ) -> fidl::Result<()> {
118            encoder.debug_check_bounds::<Self>(offset);
119            encoder.write_num(self.into_primitive(), offset);
120            Ok(())
121        }
122    }
123
124    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for HandoffError {
125        #[inline(always)]
126        fn new_empty() -> Self {
127            Self::unknown()
128        }
129
130        #[inline]
131        unsafe fn decode(
132            &mut self,
133            decoder: &mut fidl::encoding::Decoder<'_, D>,
134            offset: usize,
135            _depth: fidl::encoding::Depth,
136        ) -> fidl::Result<()> {
137            decoder.debug_check_bounds::<Self>(offset);
138            let prim = decoder.read_num::<u32>(offset);
139
140            *self = Self::from_primitive_allow_unknown(prim);
141            Ok(())
142        }
143    }
144}