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
use std::error::Error;
use std::fmt;
use std::fmt::Display;
#[derive(Debug)]
pub struct ParsingError {
description: String,
}
impl ParsingError {
pub fn new(description: &str) -> Self {
ParsingError { description: description.into() }
}
}
impl Display for ParsingError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Parsing error. Reason: {}", self.description)
}
}
impl Error for ParsingError {
fn description(&self) -> &str {
&self.description
}
fn cause(&self) -> Option<&Error> {
None
}
}