#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] pub enum ErrorKind { NeedMoreData, InvalidConnectionState, Parse, TrailingBytes, BufNotBigEnough, InvalidEventForConnectionState, BodySizeMismatch, } #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Error { pub kind: ErrorKind, pub details: &'static str, } impl Error { pub fn new(kind: ErrorKind) -> Self { Self::with_details(kind, "") } pub fn with_details(kind: ErrorKind, details: &'static str) -> Self { Error { kind, details } } } impl From for Error { fn from(value: ErrorKind) -> Self { Self::new(value) } } pub fn fail(error_kind: ErrorKind) -> Result { fail_details(error_kind, "") } pub fn fail_details(error_kind: ErrorKind, details: &'static str) -> Result { Err(Error::with_details(error_kind, details)) }