1use anyhow::Error;
2
3pub type Result<T, U = BitStreamError> = std::result::Result<T, U>;
4#[derive(Debug)]
5pub enum BitStreamError {
6 AddBits(String),
7 FlushBits(String),
8 StreamPoisoned(String),
9 NoEndMarkFound,
10 BitsOverflow(String),
11 LookFailed,
12 EmptyStream,
13 ReadOverflow,
14}
15
16impl std::fmt::Display for BitStreamError {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 write!(f, "BitStreamError: {:?}", self)
19 }
20}
21
22macro_rules! throw {
23 ($e: ident, $m: expr) => {
24 return Err(BitStreamError::$e($m.to_string()))
25 };
26 ($e: ident) => {
27 return Err(BitStreamError::$e)
28 };
29}
30
31pub(crate) use throw;
32
33impl From<BitStreamError> for Error {
34 fn from(err: BitStreamError) -> Self {
35 Error::msg(err)
36 }
37}