chinese_format/currency/
errors.rs

1use std::{error::Error, fmt::Display};
2
3/// Error for when the *dimes* of a currency value are out of range.
4///
5/// ```
6/// use chinese_format::currency::*;
7///
8/// assert_eq!(
9///     DimesOutOfRange(200).to_string(),
10///     "Dimes out of range: 200"
11/// );
12/// ```
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct DimesOutOfRange(pub u8);
15
16impl Display for DimesOutOfRange {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        write!(f, "Dimes out of range: {}", self.0)
19    }
20}
21
22impl Error for DimesOutOfRange {}
23
24/// Error for when the *cents* of a currency value are out of range.
25///
26/// ```
27/// use chinese_format::currency::*;
28///
29/// assert_eq!(
30///     CentsOutOfRange(200).to_string(),
31///     "Cents out of range: 200"
32/// );
33/// ```
34#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
35pub struct CentsOutOfRange(pub u8);
36
37impl Display for CentsOutOfRange {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        write!(f, "Cents out of range: {}", self.0)
40    }
41}
42
43impl Error for CentsOutOfRange {}