bomalloc 0.3.0

A fragmentation-aware experimental allocator built around address-span ownership
Documentation
use core::fmt;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum BoAllocError {
    OutOfMemory,
    AddressSpaceExhausted,
    InvalidConfig,
    UnsupportedPlatform,
}

impl fmt::Display for BoAllocError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::OutOfMemory => f.write_str("the backing store could not commit memory"),
            Self::AddressSpaceExhausted => {
                f.write_str("the address-space size calculation overflowed")
            }
            Self::InvalidConfig => f.write_str("invalid bomalloc configuration"),
            Self::UnsupportedPlatform => {
                f.write_str("bomalloc currently supports Windows and Linux only")
            }
        }
    }
}

impl std::error::Error for BoAllocError {}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InvariantError(pub(crate) String);

impl InvariantError {
    pub(crate) fn new(message: impl Into<String>) -> Self {
        Self(message.into())
    }
}

impl fmt::Display for InvariantError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(&self.0)
    }
}

impl std::error::Error for InvariantError {}