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
use std;
use std::fmt::{Display, Formatter};
#[derive(Debug, Clone)]
pub struct Error {
msg: String,
}
impl std::error::Error for Error {
fn description(&self) -> &str {
&self.msg
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
f.write_str(&self.msg)
}
}
impl From<String> for Error {
fn from(msg: String) -> Error {
Error { msg }
}
}
impl<'a> From<&'a str> for Error {
fn from(msg: &'a str) -> Error {
Error::from(msg.to_string())
}
}