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