Nothing to see here, move along
at main 62 lines 2.1 kB view raw
1#[must_use] 2#[non_exhaustive] 3#[derive(Debug, Clone, Copy, PartialEq, Eq)] 4#[repr(i64)] 5pub enum KernelError { 6 SlotOccupied = -1, 7 SlotEmpty = -2, 8 InvalidObject = -3, 9 InsufficientRights = -4, 10 StaleGeneration = -5, 11 PoolExhausted = -6, 12 InvalidType = -7, 13 InvalidSlot = -8, 14 InvalidAddress = -9, 15 WouldBlock = -10, 16 ResourceExhausted = -11, 17 #[allow(dead_code)] 18 NotFound = -12, 19 PermissionDenied = -13, 20 BadState = -14, 21 InvalidParameter = -15, 22 NotInitialized = -16, 23 IommuFault = -17, 24 AlreadyExists = -18, 25} 26 27impl KernelError { 28 pub const fn to_errno(self) -> i64 { 29 self as i64 30 } 31} 32 33impl core::fmt::Display for KernelError { 34 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 35 match self { 36 Self::SlotOccupied => write!(f, "slot occupied"), 37 Self::SlotEmpty => write!(f, "slot empty"), 38 Self::InvalidObject => write!(f, "invalid object"), 39 Self::InsufficientRights => write!(f, "insufficient rights"), 40 Self::StaleGeneration => write!(f, "stale generation"), 41 Self::PoolExhausted => write!(f, "pool exhausted"), 42 Self::InvalidType => write!(f, "invalid type"), 43 Self::InvalidSlot => write!(f, "invalid slot"), 44 Self::InvalidAddress => write!(f, "invalid address"), 45 Self::WouldBlock => write!(f, "would block"), 46 Self::ResourceExhausted => write!(f, "resource exhausted"), 47 Self::NotFound => write!(f, "not found"), 48 Self::PermissionDenied => write!(f, "permission denied"), 49 Self::BadState => write!(f, "bad state"), 50 Self::InvalidParameter => write!(f, "invalid parameter"), 51 Self::NotInitialized => write!(f, "not initialized"), 52 Self::IommuFault => write!(f, "iommu fault"), 53 Self::AlreadyExists => write!(f, "already exists"), 54 } 55 } 56} 57 58impl From<KernelError> for i64 { 59 fn from(e: KernelError) -> Self { 60 e.to_errno() 61 } 62}