1use bytemuck::*;
2use core::fmt::{self, Debug, Formatter};
3
4
5
6#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Zeroable)] #[repr(transparent)] pub struct WaitCode(pub(crate) u32);
9
10impl WaitCode {
11 #[doc(hidden)] pub const fn from_constant(value: u32) -> Self { Self(value) }
12
13 pub const fn to_u32(self) -> u32 { self.0 }
14
15 pub fn to_object<T: From<u8>>(self) -> Option<T> {
20 if (0 .. 64).contains(&self.0) {
21 Some((self.0 as u8).into())
22 } else {
23 None
24 }
25 }
26
27 pub fn to_abandoned<T: From<u8>>(self) -> Option<T> {
32 if (0x80 .. 0xC0).contains(&self.0) {
33 Some(((self.0 - 0x80) as u8).into())
34 } else {
35 None
36 }
37 }
38
39 pub fn to_object_u32 (self) -> Option<u32 > { self.to_object() }
40 pub fn to_object_usize (self) -> Option<usize> { self.to_object() }
41 pub fn to_abandoned_u32 (self) -> Option<u32 > { self.to_abandoned() }
42 pub fn to_abandoned_usize (self) -> Option<usize> { self.to_abandoned() }
43}
44
45impl Debug for WaitCode {
46 fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
47 if let Some(n) = self.to_object_u32() { write!(fmt, "WAIT::OBJECT_{n}") }
48 else if let Some(n) = self.to_abandoned_u32() { write!(fmt, "WAIT::ABANDONED_{n}") }
49 else if self.0 == 0xC0 { write!(fmt, "WAIT::IO_COMPLETION") }
50 else if self.0 == 0x102 { write!(fmt, "WAIT::TIMEOUT") }
51 else if self.0 == 0xFFFFFFFF { write!(fmt, "WAIT::FAILED") }
52 else { write!(fmt, "WaitCode(0x{:08X})", self.0) }
53 }
54}