use core::any;
use core::fmt;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ZeroVecError {
InvalidLength { ty: &'static str, len: usize },
ParseError { ty: &'static str },
VarZeroVecFormatError,
}
impl fmt::Display for ZeroVecError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
ZeroVecError::InvalidLength { ty, len } => {
write!(f, "Invalid length {len} for slice of type {ty}")
}
ZeroVecError::ParseError { ty } => {
write!(f, "Could not parse bytes to slice of type {ty}")
}
ZeroVecError::VarZeroVecFormatError => {
write!(f, "Invalid format for VarZeroVec buffer")
}
}
}
}
impl ZeroVecError {
pub fn parse<T: ?Sized + 'static>() -> ZeroVecError {
ZeroVecError::ParseError {
ty: any::type_name::<T>(),
}
}
pub fn length<T: ?Sized + 'static>(len: usize) -> ZeroVecError {
ZeroVecError::InvalidLength {
ty: any::type_name::<T>(),
len,
}
}
}
#[cfg(feature = "std")]
impl ::std::error::Error for ZeroVecError {}