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