osom_lib_strings 0.1.1

ABI-stable string types and helpers for osom_lib.
Documentation
use osom_lib_alloc::traits::AllocationError;
use osom_lib_primitives::length::LengthError;
use osom_lib_reprc::macros::reprc;

/// Represents potential errors when working with `ImmutableString`.
#[reprc]
#[repr(u8)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum ImmutableStringError {
    /// The internal allocator returned an error.
    AllocationError = 0,

    /// Max length exceeded.
    MaxLengthExceeded = 1,
}

impl From<AllocationError> for ImmutableStringError {
    fn from(_: AllocationError) -> Self {
        Self::AllocationError
    }
}

impl From<LengthError> for ImmutableStringError {
    fn from(_: LengthError) -> Self {
        Self::MaxLengthExceeded
    }
}

impl core::fmt::Display for ImmutableStringError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            ImmutableStringError::AllocationError => write!(f, "ImmutableStringError::AllocationError"),
            ImmutableStringError::MaxLengthExceeded => write!(f, "ImmutableStringError::MaxLengthExceeded"),
        }
    }
}