#![allow(unused_imports)]
#![allow(dead_code)]
pub use crate::cfg::*;
use core::error;
#[derive(Debug)]
pub enum Error {
Invalid,
Unsupported,
LengthExceedsMax,
LengthMismatch,
NonZeroPadding,
#[cfg(feature = "alloc")]
InvalidHex,
InvalidUTF8,
DepthLimitExceeded,
LengthLimitExceeded,
}
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
core::mem::discriminant(self) == core::mem::discriminant(other)
}
}
impl error::Error for Error {}
use core::array::TryFromSliceError;
use core::fmt;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Invalid => write!(f, "xdr value invalid"),
Error::Unsupported => write!(f, "xdr value unsupported"),
Error::LengthExceedsMax => {
write!(f, "xdr value max length exceeded")
}
Error::LengthMismatch => {
write!(f, "xdr value length does not match")
}
Error::NonZeroPadding => {
write!(f, "xdr padding contains non-zero bytes")
}
#[cfg(feature = "alloc")]
Error::InvalidHex => write!(f, "hex invalid"),
Error::InvalidUTF8 => write!(f, "utf8 invalid"),
Error::DepthLimitExceeded => write!(f, "depth limit exceeded"),
Error::LengthLimitExceeded => write!(f, "length limit exceeded"),
}
}
}
impl From<TryFromSliceError> for Error {
fn from(_: TryFromSliceError) -> Error {
Error::LengthMismatch
}
}
impl From<core::str::Utf8Error> for Error {
fn from(_: core::str::Utf8Error) -> Self {
Error::InvalidUTF8
}
}
#[cfg(feature = "alloc")]
impl From<FromUtf8Error> for Error {
fn from(_: FromUtf8Error) -> Self {
Error::InvalidUTF8
}
}