byte_transcoder/
reader_error.rs

1use std::fmt::{Debug, Formatter};
2use std::{error, fmt};
3
4pub type ByteReaderResult<T> = Result<T, ByteReaderError>;
5
6#[expect(clippy::module_name_repetitions)]
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum ByteReaderError {
9    NotEnoughBytes {
10        index_offset: usize,
11        buffer_length: usize,
12    },
13    SliceConversionFailure,
14    InvalidUtf8,
15}
16
17impl error::Error for ByteReaderError {}
18
19impl fmt::Display for ByteReaderError {
20    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
21        match self {
22            ByteReaderError::NotEnoughBytes {
23                index_offset,
24                buffer_length,
25            } => write!(
26                f,
27                "Attempted to read past the end of the buffer. Index Offset: '{index_offset}', Buffer Length: '{buffer_length}'.",
28            ),
29            ByteReaderError::SliceConversionFailure => {
30                write!(f, "Failed to convert slice to a fixed-size array.")
31            }
32            ByteReaderError::InvalidUtf8 => write!(f, "Attempted to read invalid UTF-8 bytes."),
33        }
34    }
35}