-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.rs
35 lines (29 loc) · 926 Bytes
/
error.rs
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
use core::fmt;
use std::{
error::Error,
fmt::{Debug, Display, Formatter, Result},
ops::RangeInclusive,
};
/// The error type for when a value is out of range.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OutOfRangeError<T: Debug + Display>(pub(crate) RangeInclusive<T>);
impl<T: Debug + Display> Display for OutOfRangeError<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"Out Of Range Error [{} - {}]",
self.0.start(),
self.0.end()
)
}
}
impl<T: Debug + Display> Error for OutOfRangeError<T> {}
/// The error type for when a value cannot be parsed from a string.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ParseError(pub(crate) String);
impl Display for ParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", self.0)
}
}
impl Error for ParseError {}