rarena_allocator/
error.rspub use dbutils::error::*;
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
#[derive(Debug)]
pub(crate) struct MagicVersionMismatch {
expected_version: u16,
found_version: u16,
}
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
impl MagicVersionMismatch {
#[inline]
pub(crate) const fn new(expected_version: u16, found_version: u16) -> Self {
Self {
expected_version,
found_version,
}
}
}
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
impl core::fmt::Display for MagicVersionMismatch {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"ARENA's magic version mismatch: expected version {}, but found version {}.",
self.expected_version, self.found_version
)
}
}
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
impl core::error::Error for MagicVersionMismatch {}
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
#[derive(Debug)]
pub(crate) struct VersionMismatch {
expected_version: u16,
found_version: u16,
}
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
impl VersionMismatch {
#[inline]
pub(crate) const fn new(expected_version: u16, found_version: u16) -> Self {
Self {
expected_version,
found_version,
}
}
}
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
impl core::fmt::Display for VersionMismatch {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"ARENA's version mismatch: expected version {}, but found version {}.",
self.expected_version, self.found_version
)
}
}
#[cfg(all(feature = "memmap", not(target_family = "wasm")))]
impl core::error::Error for VersionMismatch {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
InsufficientSpace {
requested: u32,
available: u32,
},
ReadOnly,
OutOfBounds {
offset: usize,
allocated: usize,
},
DecodeVarintError(dbutils::leb128::DecodeVarintError),
}
impl From<dbutils::leb128::DecodeVarintError> for Error {
#[inline]
fn from(e: dbutils::leb128::DecodeVarintError) -> Self {
Self::DecodeVarintError(e)
}
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InsufficientSpace {
requested,
available,
} => write!(
f,
"Allocation failed: requested size is {}, but only {} is available",
requested, available
),
Self::ReadOnly => write!(f, "Arena is read-only"),
Self::OutOfBounds { offset, allocated } => write!(
f,
"Index out of bounds: offset {} is out of range, the current allocated size is {}",
offset, allocated
),
Self::DecodeVarintError(e) => e.fmt(f),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}