use anyhow::Error;
pub type Result<T, U = BitStreamError> = std::result::Result<T, U>;
#[derive(Debug)]
pub enum BitStreamError {
AddBits(String),
FlushBits(String),
StreamPoisoned(String),
NoEndMarkFound,
BitsOverflow(String),
LookFailed,
EmptyStream,
ReadOverflow,
}
impl std::fmt::Display for BitStreamError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "BitStreamError: {:?}", self)
}
}
macro_rules! throw {
($e: ident, $m: expr) => {
return Err(BitStreamError::$e($m.to_string()))
};
($e: ident) => {
return Err(BitStreamError::$e)
};
}
pub(crate) use throw;
impl From<BitStreamError> for Error {
fn from(err: BitStreamError) -> Self {
Error::msg(err)
}
}