1#![allow(unused_imports)]
2#![allow(dead_code)]
3
4pub use crate::cfg::*;
5
6use core::error;
7
8#[derive(Debug)]
12pub enum Error {
13 Invalid,
15 Unsupported,
17 LengthExceedsMax,
22 LengthMismatch,
24 NonZeroPadding,
26 #[cfg(feature = "alloc")]
30 InvalidHex,
31 InvalidUTF8,
35 DepthLimitExceeded,
37 LengthLimitExceeded,
39}
40
41impl PartialEq for Error {
42 fn eq(&self, other: &Self) -> bool {
43 core::mem::discriminant(self) == core::mem::discriminant(other)
44 }
45}
46
47impl error::Error for Error {}
48
49use core::array::TryFromSliceError;
50use core::fmt;
51
52impl fmt::Display for Error {
53 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54 match self {
55 Error::Invalid => write!(f, "xdr value invalid"),
56 Error::Unsupported => write!(f, "xdr value unsupported"),
57 Error::LengthExceedsMax => {
58 write!(f, "xdr value max length exceeded")
59 }
60 Error::LengthMismatch => {
61 write!(f, "xdr value length does not match")
62 }
63 Error::NonZeroPadding => {
64 write!(f, "xdr padding contains non-zero bytes")
65 }
66 #[cfg(feature = "alloc")]
67 Error::InvalidHex => write!(f, "hex invalid"),
68 Error::InvalidUTF8 => write!(f, "utf8 invalid"),
69 Error::DepthLimitExceeded => write!(f, "depth limit exceeded"),
70 Error::LengthLimitExceeded => write!(f, "length limit exceeded"),
71 }
72 }
73}
74
75impl From<TryFromSliceError> for Error {
76 fn from(_: TryFromSliceError) -> Error {
77 Error::LengthMismatch
78 }
79}
80
81impl From<core::str::Utf8Error> for Error {
82 fn from(_: core::str::Utf8Error) -> Self {
83 Error::InvalidUTF8
84 }
85}
86
87#[cfg(feature = "alloc")]
88impl From<FromUtf8Error> for Error {
89 fn from(_: FromUtf8Error) -> Self {
90 Error::InvalidUTF8
91 }
92}