ht16k33/
errors.rs

1use core::fmt;
2
3/// Errors encountered during validation.
4#[derive(Debug)]
5pub enum ValidationError {
6    /// The value is too large.
7    ValueTooLarge {
8        /// Name of the value.
9        name: &'static str,
10        /// Value that failed validation.
11        value: u8,
12        /// Limit that the value exceeded.
13        limit: u8,
14        /// Whether the limit is inclusive or not.
15        inclusive: bool,
16    },
17}
18
19#[cfg(feature = "std")]
20extern crate std;
21
22#[cfg(feature = "std")]
23impl std::error::Error for ValidationError {}
24
25impl fmt::Display for ValidationError {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        match self {
28            ValidationError::ValueTooLarge {
29                name,
30                value,
31                limit,
32                inclusive,
33            } => write!(
34                f,
35                "'{}' value [{}] must be less than (or equal: {}) [{}])",
36                name, value, limit, inclusive
37            ),
38        }
39    }
40}