use core::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ArenaError {
CapacityExhausted,
}
impl fmt::Display for ArenaError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::CapacityExhausted => {
f.write_str("arena is full: cannot allocate beyond u32::MAX values")
}
}
}
}
impl core::error::Error for ArenaError {}
#[cfg(test)]
mod tests {
extern crate alloc;
use alloc::string::ToString;
use super::*;
#[test]
fn test_capacity_exhausted_display_is_actionable() {
let text = ArenaError::CapacityExhausted.to_string();
assert!(text.contains("u32::MAX"), "{text}");
}
#[test]
fn test_error_is_copy_and_equatable() {
let a = ArenaError::CapacityExhausted;
let b = a;
assert_eq!(a, b);
}
}