use std::{fmt, result};
pub type Result<T, E = YadaError> = result::Result<T, E>;
#[derive(Debug, Eq, PartialEq)]
pub enum YadaError {
EmptyKeyset,
EmptyKey,
NullByte,
DuplicateKey,
UnsortedKeyset,
ValueTooLarge { max: u32 },
TooManyUnits { max: u32 },
EmptyDoubleArray,
UnalignedDoubleArray { len: usize, unit_size: usize },
UnalignedDoubleArrayBlocks { num_units: usize, block_size: usize },
InvalidDoubleArrayUnit {
index: usize,
offset: usize,
num_units: usize,
},
}
impl fmt::Display for YadaError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::EmptyKeyset => write!(f, "keyset must not be empty"),
Self::EmptyKey => write!(f, "keyset must not contain an empty key"),
Self::NullByte => write!(f, "keys must not contain NULL"),
Self::DuplicateKey => write!(f, "keyset must not contain duplicated keys"),
Self::UnsortedKeyset => write!(f, "keyset must be sorted"),
Self::ValueTooLarge { max } => {
write!(f, "input value must be no greater than {max}")
}
Self::TooManyUnits { max } => {
write!(f, "num_units must be no greater than {max}")
}
Self::EmptyDoubleArray => write!(f, "double-array trie must not be empty"),
Self::UnalignedDoubleArray { len, unit_size } => write!(
f,
"double-array trie byte length ({len}) must be a multiple of unit size ({unit_size})"
),
Self::UnalignedDoubleArrayBlocks {
num_units,
block_size,
} => write!(
f,
"double-array trie unit length ({num_units}) must be a multiple of block size ({block_size})"
),
Self::InvalidDoubleArrayUnit {
index,
offset,
num_units,
} => write!(
f,
"double-array trie unit at index {index} can refer to offset {offset}, but num_units is {num_units}"
),
}
}
}
impl std::error::Error for YadaError {}