use crate::{BLOCK_ALIGNMENT, N};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Error {
InvalidBlockSize(usize),
BlockSizeMismatch {
expected: usize,
got: usize,
},
DuplicateIndex(usize),
IndexOutOfRange(usize),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::InvalidBlockSize(size) => write!(
f,
"block size {size} is not a positive multiple of {BLOCK_ALIGNMENT}"
),
Error::BlockSizeMismatch { expected, got } => write!(
f,
"block size mismatch: expected {expected} bytes, got {got} bytes"
),
Error::DuplicateIndex(idx) => write!(f, "duplicate block index {idx}"),
Error::IndexOutOfRange(idx) => {
write!(f, "block index {idx} is out of range (must be less than {N})")
}
}
}
}
impl std::error::Error for Error {}