Skip to main content

bit_buf/
error.rs

1use core::fmt::{self, Display};
2
3/// Error from checked operations
4#[derive(Debug, PartialEq)]
5pub enum Error {
6  /// An aligned operation failed due to the internal cursor not being byte-aligned
7  Unaligned,
8  /// An operation failed due to storage not containing enough data
9  OutOfBounds,
10  /// The requested bit count exceeds the maximum width for the operating type
11  InvalidBitCount,
12}
13
14impl Display for Error {
15  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16    use Error::*;
17    match self {
18      OutOfBounds => write!(f, "BitBuf: operation out of bounds"),
19      Unaligned => write!(f, "BitBuf: aligned operation on unaligned cursor"),
20      InvalidBitCount => write!(f, "BitBuf: requested bit count exceeds type width"),
21    }
22  }
23}
24
25impl core::error::Error for Error {}