1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug)]
5pub struct ParserError {
6 pub message: String,
7}
8
9impl Error for ParserError {}
10
11impl fmt::Display for ParserError {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 write!(f, "{}", self.message)
14 }
15}
16
17impl From<std::str::ParseBoolError> for ParserError {
18 fn from(e: std::str::ParseBoolError) -> Self {
19 ParserError {
20 message: format!("Could not parse boolean: {}", e.to_string())
21 }
22 }
23}
24
25impl From<std::num::ParseIntError> for ParserError {
26 fn from(e: std::num::ParseIntError) -> Self {
27 ParserError {
28 message: format!("Could not parse integer: {}", e.to_string())
29 }
30 }
31}
32
33impl From<std::num::ParseFloatError> for ParserError {
34 fn from(e: std::num::ParseFloatError) -> Self {
35 ParserError {
36 message: format!("Could not parse float: {}", e.to_string())
37 }
38 }
39}