chinese_format/gregorian/time/
errors.rs

1use std::{error::Error, fmt::Display};
2
3/// Error for when the *hour* part of a time expression is out of range.
4///
5/// ```
6/// use chinese_format::gregorian::*;
7///
8/// assert_eq!(
9///     HourOutOfRange(90).to_string(),
10///     "Hour out of range: 90"
11/// );
12/// ```
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct HourOutOfRange(pub u8);
15
16impl Display for HourOutOfRange {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        write!(f, "Hour out of range: {}", self.0)
19    }
20}
21
22impl Error for HourOutOfRange {}
23
24/// Error for when the *minute* part of a time expression is out of range.
25///
26/// ```
27/// use chinese_format::gregorian::*;
28///
29/// assert_eq!(
30///     MinuteOutOfRange(90).to_string(),
31///     "Minute out of range: 90"
32/// );
33/// ```
34#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
35pub struct MinuteOutOfRange(pub u8);
36
37impl Display for MinuteOutOfRange {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        write!(f, "Minute out of range: {}", self.0)
40    }
41}
42
43impl Error for MinuteOutOfRange {}
44
45/// Error for when the *second* part of a time expression is out of range.
46///
47/// ```
48/// use chinese_format::gregorian::*;
49///
50/// assert_eq!(
51///     SecondOutOfRange(90).to_string(),
52///     "Second out of range: 90"
53/// );
54/// ```
55#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
56pub struct SecondOutOfRange(pub u8);
57
58impl Display for SecondOutOfRange {
59    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60        write!(f, "Second out of range: {}", self.0)
61    }
62}
63
64impl Error for SecondOutOfRange {}