attachable-slab-allocator 0.1.0

A high-performance, $O(1)$, Master-Slave slab allocator designed for `no_std` environments, kernels, and embedded systems. This library provides fixed-size memory management with RAII safety while remaining completely agnostic of the underlying memory provider.
Documentation
/// Represents the types of errors that can occur during memory allocation operations.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SlabError {
    /// The requested memory block could not be allocated because no suitable
    /// free space is available.
    OutOfMemory,
    /// The provided address or size does not meet the alignment requirements
    /// for the specific operation (e.g., page alignment).
    AlignmentMismatch,
    /// The provided pointer is invalid or null.
    InvalidPointer,
    /// A fatal system error occurred.
    FatalError,
}

impl core::fmt::Display for SlabError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::OutOfMemory => write!(f, "Memory allocation failed: Out of memory"),
            Self::AlignmentMismatch => {
                write!(f, "Memory alignment is incorrect for this operation")
            }
            Self::InvalidPointer => write!(f, "Attempted to use an invalid or null pointer"),
            Self::FatalError => write!(f, "A fatal system error occurred"),
        }
    }
}

impl core::error::Error for SlabError {
    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
        None
    }
}

/// A specialized `Result` type for memory allocation operations.
///
/// This alias simplifies function signatures by defaulting the error type
/// to [`AllocatorError`].
pub type Result<T> = core::result::Result<T, SlabError>;