1use std::fmt::Formatter;
2
3#[derive(Debug)]
4pub enum BitReadWriteError {
5 InvalidBitCount(usize),
6 UnexpectedEof,
7 UnalignedAccess,
8}
9
10impl std::fmt::Display for BitReadWriteError {
11 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
12 match self {
13 BitReadWriteError::InvalidBitCount(n) => {
14 write!(f, "Bit count must be between 1-64, got {}", n)
15 }
16 BitReadWriteError::UnexpectedEof => write!(f, "Unexpected end of stream"),
17 BitReadWriteError::UnalignedAccess => {
18 write!(f, "Attempted to consume bytes while bits are buffered")
19 }
20 }
21 }
22}
23
24impl std::error::Error for BitReadWriteError {}
25
26impl From<BitReadWriteError> for std::io::Error {
27 fn from(e: BitReadWriteError) -> Self {
28 std::io::Error::new(std::io::ErrorKind::Other, e.to_string())
29 }
30}