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
use std::error;
use std::fmt::{self, Display, Formatter};
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
ParseError(String),
NameError(String),
}
impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
match *self {
Self::ParseError(ref message) => write!(fmt, "ParseError: {}", message),
Self::NameError(ref message) => write!(fmt, "NameError: {}", message),
}
}
}
impl error::Error for Error {
#[must_use]
fn description(&self) -> &str {
match *self {
Self::ParseError(ref message) | Self::NameError(ref message) => message,
}
}
#[must_use]
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
Self::ParseError(_) | Self::NameError(_) => None,
}
}
}