1use crate::{BLOCK_ALIGNMENT, N};
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5#[non_exhaustive]
6pub enum Error {
7 InvalidBlockSize(usize),
9
10 BlockSizeMismatch {
12 expected: usize,
14 got: usize,
16 },
17
18 DuplicateIndex(usize),
20
21 IndexOutOfRange(usize),
23}
24
25impl std::fmt::Display for Error {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Error::InvalidBlockSize(size) => write!(
29 f,
30 "block size {size} is not a positive multiple of {BLOCK_ALIGNMENT}"
31 ),
32 Error::BlockSizeMismatch { expected, got } => write!(
33 f,
34 "block size mismatch: expected {expected} bytes, got {got} bytes"
35 ),
36 Error::DuplicateIndex(idx) => write!(f, "duplicate block index {idx}"),
37 Error::IndexOutOfRange(idx) => {
38 write!(f, "block index {idx} is out of range (must be less than {N})")
39 }
40 }
41 }
42}
43
44impl std::error::Error for Error {}