1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use chrono;
use regex;
use std;
use std::error::Error as StdError;
#[derive(Debug)]
pub enum Error {
Parsing(chrono::ParseError),
Regex(regex::Error),
Ordering,
OutOfRange,
Empty,
NotContinuous,
NoStart,
NoEnd,
LocalAmbigious,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Error::Parsing(ref e) => write!(f, "{}", e),
Error::Regex(ref e) => write!(f, "{}", e),
_ => write!(f, "{}", self.description()),
}
}
}
impl StdError for Error {
fn description(&self) -> &str {
match *self {
Error::Parsing(..) => "An error occured while parsing a value",
Error::Regex(..) => "An error occured while creating a regular expression",
Error::Ordering => "The left value is not smaller than the right value",
Error::OutOfRange => "This resulting value is out of range",
Error::Empty => "The resulting span is empty",
Error::NotContinuous => "The resulting span is not continuous",
Error::NoStart => "The resulting span has no start value",
Error::NoEnd => "The resulting span has no end value",
Error::LocalAmbigious => "The resulting local time is ambigious",
}
}
}
impl std::convert::From<chrono::ParseError> for Error {
fn from(e: chrono::ParseError) -> Self {
Error::Parsing(e)
}
}
impl std::convert::From<regex::Error> for Error {
fn from(e: regex::Error) -> Self {
Error::Regex(e)
}
}