#[non_exhaustive]
#[derive(Debug)]
pub enum EncodeError {
UnexpectedEnd,
RefCellAlreadyBorrowed {
inner: core::cell::BorrowError,
type_name: &'static str,
},
Other(&'static str),
#[cfg(feature = "alloc")]
OtherString(alloc::string::String),
#[cfg(feature = "std")]
InvalidPathCharacters,
#[cfg(feature = "std")]
Io {
error: std::io::Error,
index: usize,
},
#[cfg(feature = "std")]
LockFailed {
type_name: &'static str,
},
#[cfg(feature = "std")]
InvalidSystemTime {
inner: std::time::SystemTimeError,
time: std::time::SystemTime,
},
#[cfg(feature = "serde")]
Serde(crate::features::serde::EncodeError),
}
impl core::fmt::Display for EncodeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self)
}
}
#[non_exhaustive]
#[derive(Debug, PartialEq)]
pub enum DecodeError {
UnexpectedEnd,
LimitExceeded,
InvalidIntegerType {
expected: IntegerType,
found: IntegerType,
},
NonZeroTypeIsZero {
non_zero_type: IntegerType,
},
UnexpectedVariant {
type_name: &'static str,
allowed: AllowedEnumVariants,
found: u32,
},
Utf8(core::str::Utf8Error),
InvalidCharEncoding([u8; 4]),
InvalidBooleanValue(u8),
ArrayLengthMismatch {
required: usize,
found: usize,
},
OutsideUsizeRange(u64),
EmptyEnum {
type_name: &'static str,
},
InvalidDuration {
secs: u64,
nanos: u32,
},
InvalidSystemTime {
duration: core::time::Duration,
},
#[cfg(feature = "std")]
CStringNulError {
inner: std::ffi::NulError,
},
#[cfg(feature = "alloc")]
OtherString(alloc::string::String),
#[cfg(feature = "serde")]
Serde(crate::features::serde::DecodeError),
}
impl core::fmt::Display for DecodeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self)
}
}
impl DecodeError {
pub(crate) fn change_integer_type_to_signed(self) -> DecodeError {
match self {
Self::InvalidIntegerType { expected, found } => Self::InvalidIntegerType {
expected: expected.into_signed(),
found: found.into_signed(),
},
other => other,
}
}
}
#[non_exhaustive]
#[derive(Debug, PartialEq)]
pub enum AllowedEnumVariants {
#[allow(missing_docs)]
Range { min: u32, max: u32 },
Allowed(&'static [u32]),
}
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum IntegerType {
U8,
U16,
U32,
U64,
U128,
Usize,
I8,
I16,
I32,
I64,
I128,
Isize,
Reserved,
}
impl IntegerType {
pub(crate) fn into_signed(self) -> Self {
match self {
Self::U8 => Self::I8,
Self::U16 => Self::I16,
Self::U32 => Self::I32,
Self::U64 => Self::I64,
Self::U128 => Self::I128,
Self::Usize => Self::Isize,
other => other,
}
}
}