le_stream/
error.rs

1use core::fmt::{Display, Formatter};
2
3/// Result type with [`Error`] as error variant.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// Error type for byte stream operations.
7#[derive(Clone, Debug, Eq, Hash, PartialEq)]
8pub enum Error {
9    /// The byte stream was not exhausted.
10    StreamNotExhausted(u8),
11    /// The byte stream ended prematurely.
12    UnexpectedEndOfStream,
13}
14
15impl Display for Error {
16    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
17        match self {
18            Self::StreamNotExhausted(next_byte) => {
19                write!(f, "byte stream not exhausted: [{next_byte:#04X?}, ..]")
20            }
21            Self::UnexpectedEndOfStream => write!(f, "unexpected end of stream"),
22        }
23    }
24}
25
26impl core::error::Error for Error {}