weakauras_codec_base64/
error.rs1use core::fmt;
5#[cfg(any(test, feature = "std"))]
6use std::error;
7
8#[derive(Clone, Debug, PartialEq, Eq)]
10pub enum DecodeError {
11 InvalidByte(usize),
13 InvalidLength,
15}
16
17impl fmt::Display for DecodeError {
18 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19 match *self {
20 Self::InvalidByte(offset) => write!(f, "Invalid byte at offset {}", offset),
21 Self::InvalidLength => write!(f, "Invalid length"),
22 }
23 }
24}
25
26#[cfg(any(test, feature = "std"))]
27impl error::Error for DecodeError {}
28
29#[derive(Clone, Debug, PartialEq, Eq)]
31pub enum DecodeIntoSliceError {
32 DecodeError(DecodeError),
34 OutputSliceIsTooSmall,
36}
37
38impl From<DecodeError> for DecodeIntoSliceError {
39 fn from(e: DecodeError) -> Self {
40 Self::DecodeError(e)
41 }
42}
43
44impl fmt::Display for DecodeIntoSliceError {
45 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46 match self {
47 Self::DecodeError(inner) => inner.fmt(f),
48 Self::OutputSliceIsTooSmall => write!(f, "Output slice is too small"),
49 }
50 }
51}
52
53#[cfg(any(test, feature = "std"))]
54impl error::Error for DecodeIntoSliceError {
55 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
56 match self {
57 Self::DecodeError(inner) => Some(inner),
58 Self::OutputSliceIsTooSmall => None,
59 }
60 }
61}
62
63#[derive(Clone, Debug, PartialEq, Eq)]
65pub enum EncodeError {
66 DataIsTooLarge,
68}
69
70impl fmt::Display for EncodeError {
71 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
72 match self {
73 Self::DataIsTooLarge => write!(f, "Data is too large"),
74 }
75 }
76}
77
78#[cfg(any(test, feature = "std"))]
79impl error::Error for EncodeError {}
80
81#[derive(Clone, Debug, PartialEq, Eq)]
83pub enum EncodeIntoSliceError {
84 EncodeError(EncodeError),
86 OutputSliceIsTooSmall,
88}
89
90impl From<EncodeError> for EncodeIntoSliceError {
91 fn from(e: EncodeError) -> Self {
92 Self::EncodeError(e)
93 }
94}
95
96impl fmt::Display for EncodeIntoSliceError {
97 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
98 match self {
99 Self::EncodeError(inner) => inner.fmt(f),
100 Self::OutputSliceIsTooSmall => write!(f, "Output slice is too small"),
101 }
102 }
103}
104
105#[cfg(any(test, feature = "std"))]
106impl error::Error for EncodeIntoSliceError {
107 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
108 match self {
109 Self::EncodeError(inner) => Some(inner),
110 Self::OutputSliceIsTooSmall => None,
111 }
112 }
113}