#[derive(Debug, thiserror::Error)]
#[error("primitive decode failed")]
#[non_exhaustive]
pub struct PrimitiveError {
#[source]
pub kind: PrimitiveErrorKind,
}
impl PrimitiveError {
#[must_use]
pub const fn new(kind: PrimitiveErrorKind) -> Self {
Self { kind }
}
}
impl From<PrimitiveErrorKind> for PrimitiveError {
fn from(kind: PrimitiveErrorKind) -> Self {
Self::new(kind)
}
}
#[derive(Debug, thiserror::Error)]
#[expect(
variant_size_differences,
reason = "InsufficientData carries usize×2 context; InvalidVarint a single u8. Boxing the \
larger variant would slow the hot path for negligible memory savings on a \
short-lived error."
)]
#[non_exhaustive]
pub enum PrimitiveErrorKind {
#[error("insufficient data: needed {needed} bytes, only {available} available")]
InsufficientData {
needed: usize,
available: usize,
},
#[error("invalid varint: continuation bit set past byte {max_bytes}")]
InvalidVarint {
max_bytes: u8,
},
#[error("compact length {length} exceeds the i32 maximum")]
LengthOutOfRange {
length: u32,
},
}