use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CapacityError {
resource: &'static str,
}
impl CapacityError {
#[must_use]
pub const fn new(resource: &'static str) -> Self {
Self { resource }
}
#[must_use]
pub const fn resource(self) -> &'static str {
self.resource
}
}
impl fmt::Display for CapacityError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"{} exceeds its supported capacity",
self.resource
)
}
}
impl std::error::Error for CapacityError {}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TableError {
Capacity(CapacityError),
ReversedRange {
table: &'static str,
},
MissingIndex {
table: &'static str,
},
}
impl fmt::Display for TableError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Capacity(error) => error.fmt(formatter),
Self::ReversedRange { table } => write!(formatter, "{table} child range is reversed"),
Self::MissingIndex { table } => write!(formatter, "{table} index does not exist"),
}
}
}
impl std::error::Error for TableError {}