alphanumeric_stepper/
errors.rs1use core::{
2 error::Error,
3 fmt::{self, Display, Formatter},
4};
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum AlphanumericStepperBuildError {
8 InvalidWidth,
9}
10
11impl Display for AlphanumericStepperBuildError {
12 #[inline]
13 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
14 match self {
15 Self::InvalidWidth => f.write_str("invalid width"),
16 }
17 }
18}
19
20impl Error for AlphanumericStepperBuildError {}
21
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum AlphanumericStepperEncodeError {
24 NumberOutOfRange,
25}
26
27impl Display for AlphanumericStepperEncodeError {
28 #[inline]
29 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::NumberOutOfRange => f.write_str("number out of range"),
32 }
33 }
34}
35
36impl Error for AlphanumericStepperEncodeError {}
37
38#[derive(Debug, Clone, PartialEq, Eq)]
39pub enum AlphanumericStepperDecodeError {
40 InvalidLength,
41 InvalidCharacter,
42}
43
44impl Display for AlphanumericStepperDecodeError {
45 #[inline]
46 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
47 match self {
48 Self::InvalidLength => f.write_str("invalid length"),
49 Self::InvalidCharacter => f.write_str("invalid character"),
50 }
51 }
52}
53
54impl Error for AlphanumericStepperDecodeError {}
55
56#[cfg(feature = "std")]
57#[derive(Debug)]
58pub enum AlphanumericStepperEncodeWriteError {
59 NumberOutOfRange,
60 IOError(std::io::Error),
61}
62
63#[cfg(feature = "std")]
64impl Display for AlphanumericStepperEncodeWriteError {
65 #[inline]
66 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
67 match self {
68 Self::NumberOutOfRange => f.write_str("number out of range"),
69 Self::IOError(error) => Display::fmt(error, f),
70 }
71 }
72}
73
74#[cfg(feature = "std")]
75impl From<std::io::Error> for AlphanumericStepperEncodeWriteError {
76 #[inline]
77 fn from(error: std::io::Error) -> Self {
78 Self::IOError(error)
79 }
80}
81
82#[cfg(feature = "std")]
83impl From<AlphanumericStepperEncodeError> for AlphanumericStepperEncodeWriteError {
84 #[inline]
85 fn from(error: AlphanumericStepperEncodeError) -> Self {
86 match error {
87 AlphanumericStepperEncodeError::NumberOutOfRange => Self::NumberOutOfRange,
88 }
89 }
90}
91
92#[cfg(feature = "std")]
93impl Error for AlphanumericStepperEncodeWriteError {}