bincake_core/error.rs
1//! Provides types to denote errors during serialization/deserialization.
2
3/// Denotes a fatal error during decoding.
4#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
5pub enum DecodeError {
6 #[error("[{pos:#04x}]: Stream is exhausted")]
7 Exhausted { pos: usize },
8
9 #[error("[{pos:#04x}]: {cause}")]
10 Other { pos: usize, cause: String },
11}
12
13/// Denotes a fatal error during encoding.
14#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
15pub enum EncodeError {
16 /// Denotes that the length of an array is to large to be serialized as a prefix of its elements.
17 ///
18 /// Here, an array refers to any contiguous sequence of elements.
19 ///
20 /// This error may be raised when the length of a `String` is too large for a `u32` prefix,
21 /// or when the length of a `VecN` is too large for its specified prefix.
22 #[error("Length {len} cannot fit in prefix of size {prefix_size} bytes")]
23 LengthExceedsPrefix { prefix_size: u8, len: usize },
24
25 #[error("{cause}")]
26 Other { cause: String },
27}