fidl_fuchsia_time_alarms__common/
fidl_fuchsia_time_alarms__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
11pub type AlarmId = String;
12
13/// WakeAlarmsError describes the error code that can be returned from wake
14/// alarm API calls.
15#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum WakeAlarmsError {
17    /// Denotes new failure mode which has not been assigned an error code yet.
18    ///
19    /// Expect this failure mode to be assigned a more specific error code in
20    /// the future versions of this API. This is not a bug, but an indication
21    /// that you may need to update the API version.
22    Unspecified,
23    /// This alarm was canceled, or rescheduled by the API user.
24    Dropped,
25    /// The server end encountered an error internal to its code, which should
26    /// not ever happen in normal operation. Receiving this error means that the
27    /// server end of the connection has a bug that must be fixed.
28    Internal,
29    #[doc(hidden)]
30    __SourceBreaking { unknown_ordinal: u32 },
31}
32
33/// Pattern that matches an unknown `WakeAlarmsError` member.
34#[macro_export]
35macro_rules! WakeAlarmsErrorUnknown {
36    () => {
37        _
38    };
39}
40
41impl WakeAlarmsError {
42    #[inline]
43    pub fn from_primitive(prim: u32) -> Option<Self> {
44        match prim {
45            1 => Some(Self::Unspecified),
46            2 => Some(Self::Dropped),
47            3 => Some(Self::Internal),
48            _ => None,
49        }
50    }
51
52    #[inline]
53    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
54        match prim {
55            1 => Self::Unspecified,
56            2 => Self::Dropped,
57            3 => Self::Internal,
58            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
59        }
60    }
61
62    #[inline]
63    pub fn unknown() -> Self {
64        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
65    }
66
67    #[inline]
68    pub const fn into_primitive(self) -> u32 {
69        match self {
70            Self::Unspecified => 1,
71            Self::Dropped => 2,
72            Self::Internal => 3,
73            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
74        }
75    }
76
77    #[inline]
78    pub fn is_unknown(&self) -> bool {
79        match self {
80            Self::__SourceBreaking { unknown_ordinal: _ } => true,
81            _ => false,
82        }
83    }
84}
85
86#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
87pub struct WakeAlarmsCancelRequest {
88    /// The unique identifier of the alarm to cancel.
89    ///
90    /// The alarm identified by `alarm_id` is canceled, and will no
91    /// longer be expected to fire. The respective `SetAndWait` will
92    /// return [WakeAlarmsError::DROPPED].
93    ///
94    /// A race condition is possible where the alarm fires while
95    /// the Cancel call is being processed, or even slightly later.
96    /// The caller must handle such an event gracefully.
97    pub alarm_id: String,
98}
99
100impl fidl::Persistable for WakeAlarmsCancelRequest {}
101
102pub mod notifier_ordinals {
103    pub const NOTIFY: u64 = 0x23d11b31ba0d67d4;
104    pub const NOTIFY_ERROR: u64 = 0x62e915191b0113e9;
105}
106
107pub mod wake_alarms_ordinals {
108    pub const SET_AND_WAIT: u64 = 0x57ebd075ce4beba;
109    pub const CANCEL: u64 = 0x7b23a9760115e55c;
110    pub const SET: u64 = 0x1f110857e48fd72c;
111}
112
113mod internal {
114    use super::*;
115    unsafe impl fidl::encoding::TypeMarker for WakeAlarmsError {
116        type Owned = Self;
117
118        #[inline(always)]
119        fn inline_align(_context: fidl::encoding::Context) -> usize {
120            std::mem::align_of::<u32>()
121        }
122
123        #[inline(always)]
124        fn inline_size(_context: fidl::encoding::Context) -> usize {
125            std::mem::size_of::<u32>()
126        }
127
128        #[inline(always)]
129        fn encode_is_copy() -> bool {
130            false
131        }
132
133        #[inline(always)]
134        fn decode_is_copy() -> bool {
135            false
136        }
137    }
138
139    impl fidl::encoding::ValueTypeMarker for WakeAlarmsError {
140        type Borrowed<'a> = Self;
141        #[inline(always)]
142        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
143            *value
144        }
145    }
146
147    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
148        for WakeAlarmsError
149    {
150        #[inline]
151        unsafe fn encode(
152            self,
153            encoder: &mut fidl::encoding::Encoder<'_, D>,
154            offset: usize,
155            _depth: fidl::encoding::Depth,
156        ) -> fidl::Result<()> {
157            encoder.debug_check_bounds::<Self>(offset);
158            encoder.write_num(self.into_primitive(), offset);
159            Ok(())
160        }
161    }
162
163    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WakeAlarmsError {
164        #[inline(always)]
165        fn new_empty() -> Self {
166            Self::unknown()
167        }
168
169        #[inline]
170        unsafe fn decode(
171            &mut self,
172            decoder: &mut fidl::encoding::Decoder<'_, D>,
173            offset: usize,
174            _depth: fidl::encoding::Depth,
175        ) -> fidl::Result<()> {
176            decoder.debug_check_bounds::<Self>(offset);
177            let prim = decoder.read_num::<u32>(offset);
178
179            *self = Self::from_primitive_allow_unknown(prim);
180            Ok(())
181        }
182    }
183
184    impl fidl::encoding::ValueTypeMarker for WakeAlarmsCancelRequest {
185        type Borrowed<'a> = &'a Self;
186        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
187            value
188        }
189    }
190
191    unsafe impl fidl::encoding::TypeMarker for WakeAlarmsCancelRequest {
192        type Owned = Self;
193
194        #[inline(always)]
195        fn inline_align(_context: fidl::encoding::Context) -> usize {
196            8
197        }
198
199        #[inline(always)]
200        fn inline_size(_context: fidl::encoding::Context) -> usize {
201            16
202        }
203    }
204
205    unsafe impl<D: fidl::encoding::ResourceDialect>
206        fidl::encoding::Encode<WakeAlarmsCancelRequest, D> for &WakeAlarmsCancelRequest
207    {
208        #[inline]
209        unsafe fn encode(
210            self,
211            encoder: &mut fidl::encoding::Encoder<'_, D>,
212            offset: usize,
213            _depth: fidl::encoding::Depth,
214        ) -> fidl::Result<()> {
215            encoder.debug_check_bounds::<WakeAlarmsCancelRequest>(offset);
216            // Delegate to tuple encoding.
217            fidl::encoding::Encode::<WakeAlarmsCancelRequest, D>::encode(
218                (<fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(
219                    &self.alarm_id,
220                ),),
221                encoder,
222                offset,
223                _depth,
224            )
225        }
226    }
227    unsafe impl<
228            D: fidl::encoding::ResourceDialect,
229            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
230        > fidl::encoding::Encode<WakeAlarmsCancelRequest, D> for (T0,)
231    {
232        #[inline]
233        unsafe fn encode(
234            self,
235            encoder: &mut fidl::encoding::Encoder<'_, D>,
236            offset: usize,
237            depth: fidl::encoding::Depth,
238        ) -> fidl::Result<()> {
239            encoder.debug_check_bounds::<WakeAlarmsCancelRequest>(offset);
240            // Zero out padding regions. There's no need to apply masks
241            // because the unmasked parts will be overwritten by fields.
242            // Write the fields.
243            self.0.encode(encoder, offset + 0, depth)?;
244            Ok(())
245        }
246    }
247
248    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
249        for WakeAlarmsCancelRequest
250    {
251        #[inline(always)]
252        fn new_empty() -> Self {
253            Self { alarm_id: fidl::new_empty!(fidl::encoding::BoundedString<128>, D) }
254        }
255
256        #[inline]
257        unsafe fn decode(
258            &mut self,
259            decoder: &mut fidl::encoding::Decoder<'_, D>,
260            offset: usize,
261            _depth: fidl::encoding::Depth,
262        ) -> fidl::Result<()> {
263            decoder.debug_check_bounds::<Self>(offset);
264            // Verify that padding bytes are zero.
265            fidl::decode!(
266                fidl::encoding::BoundedString<128>,
267                D,
268                &mut self.alarm_id,
269                decoder,
270                offset + 0,
271                _depth
272            )?;
273            Ok(())
274        }
275    }
276}