use crate::ArenaError;
#[derive(Debug)]
pub enum Error {
Full(ArenaError),
KeyTooLarge(u64),
EntryTooLarge(u64),
Readonly,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Full(e) => write!(f, "{e}"),
Self::KeyTooLarge(size) => write!(f, "key size {} is too large", size),
Self::EntryTooLarge(size) => write!(f, "entry size {size} is too large",),
Self::Readonly => write!(f, "skipset is read only"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl From<ArenaError> for Error {
fn from(e: ArenaError) -> Self {
Self::Full(e)
}
}
#[cfg(test)]
#[test]
fn test_fmt() {
assert_eq!(
std::format!("{}", Error::KeyTooLarge(10)),
"key size 10 is too large"
);
assert_eq!(
std::format!("{}", Error::EntryTooLarge(10)),
"entry size 10 is too large"
);
assert_eq!(
std::format!("{}", Error::Full(ArenaError)),
"allocation failed because arena is full",
);
assert_eq!(std::format!("{}", Error::Readonly), "skipset is read only");
}