osom_lib_strings/immutable/
errors.rs1use osom_lib_arc::errors::CArcArrayError;
2use osom_lib_primitives::length::LengthError;
3use osom_lib_reprc::macros::reprc;
4
5#[reprc]
7#[repr(u8)]
8#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
9pub enum ImmutableStringError {
10 AllocationError = 0,
12
13 MaxLengthExceeded = 1,
15}
16
17impl From<CArcArrayError> for ImmutableStringError {
18 fn from(err: CArcArrayError) -> Self {
19 match err {
20 CArcArrayError::AllocationError => Self::AllocationError,
21 CArcArrayError::ArraySizeOutOfRange => Self::MaxLengthExceeded,
22 }
23 }
24}
25
26osom_lib_macros::unreachable_from_infallible!(ImmutableStringError);
27
28impl From<LengthError> for ImmutableStringError {
29 fn from(_: LengthError) -> Self {
30 Self::MaxLengthExceeded
31 }
32}
33
34impl core::fmt::Display for ImmutableStringError {
35 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36 match self {
37 ImmutableStringError::AllocationError => write!(f, "ImmutableStringError::AllocationError"),
38 ImmutableStringError::MaxLengthExceeded => write!(f, "ImmutableStringError::MaxLengthExceeded"),
39 }
40 }
41}
42
43#[reprc]
45#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
46pub struct MaxReferencesExceededError;
47
48osom_lib_macros::unreachable_from_infallible!(MaxReferencesExceededError);
49
50impl From<osom_lib_arc::errors::MaxReferencesExceededError> for MaxReferencesExceededError {
51 fn from(_: osom_lib_arc::errors::MaxReferencesExceededError) -> Self {
52 Self
53 }
54}