notes/
default_error.rs

1use core::fmt;
2use std::error::Error;
3use std::fmt::Display;
4
5#[derive(Debug)]
6pub struct DefaultError {
7    pub message: String,
8    pub backtrace: Option<String>,
9}
10
11impl DefaultError {
12    pub fn new(message: String) -> DefaultError {
13        DefaultError { message, backtrace: None }
14    }
15}
16
17impl Display for DefaultError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        write!(f, "{}", self.message)
20    }
21}
22
23impl From<std::io::Error> for DefaultError {
24    fn from(error: std::io::Error) -> DefaultError {
25        DefaultError {
26            message: error.to_string(),
27            backtrace: error.backtrace().map(|bt| format!("{:?}", bt)),
28        }
29    }
30}
31
32impl From<std::num::ParseIntError> for DefaultError {
33    fn from(error: std::num::ParseIntError) -> DefaultError {
34        DefaultError {
35            message: error.to_string(),
36            backtrace: error.backtrace().map(|bt| format!("{:?}", bt)),
37        }
38    }
39}