Skip to main content

osom_lib_arc/
errors.rs

1//! Holds the definition of [`CArcError`].
2use core::fmt::Display;
3
4use osom_lib_reprc::macros::reprc;
5
6/// Represents possible errors when working with [`CArc`][super::carc::CArc].
7#[reprc]
8#[repr(u8)]
9#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
10#[must_use]
11pub enum CArcError {
12    /// The underlying allocator returned an error.
13    AllocationError = 0,
14}
15
16osom_lib_macros::unreachable_from_infallible!(CArcError);
17
18impl Display for CArcError {
19    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
20        match self {
21            CArcError::AllocationError => write!(f, "CArcError::AllocationError"),
22        }
23    }
24}
25
26/// Represents possible errors when working with [`CArc`][super::carc::CArc].
27#[reprc]
28#[repr(u8)]
29#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
30#[must_use]
31pub enum CArcArrayError {
32    /// The underlying allocator returned an error.
33    AllocationError = 0,
34
35    /// The array size is out of range.
36    ArraySizeOutOfRange = 1,
37}
38
39osom_lib_macros::unreachable_from_infallible!(CArcArrayError);
40
41impl Display for CArcArrayError {
42    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
43        match self {
44            CArcArrayError::AllocationError => write!(f, "CArcArrayError::AllocationError"),
45            CArcArrayError::ArraySizeOutOfRange => write!(f, "CArcArrayError::ArraySizeOutOfRange"),
46        }
47    }
48}
49
50/// Represents an error that occurs when the maximum number of references is exceeded.
51#[reprc]
52#[repr(transparent)]
53#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
54#[must_use]
55pub struct MaxReferencesExceededError;
56
57osom_lib_macros::unreachable_from_infallible!(MaxReferencesExceededError);
58
59impl Display for MaxReferencesExceededError {
60    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61        write!(f, "MaxReferencesExceededError")
62    }
63}
64
65/// Represents possible errors when upgrading a weak reference to a strong reference.
66#[reprc]
67#[repr(u8)]
68#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
69#[must_use]
70pub enum WeakUpgradeError {
71    /// The maximum number of references is exceeded.
72    MaxReferencesExceeded = 0,
73
74    /// There are no strong references alive.
75    NoStrongReferencesAlive = 1,
76}