1use std::error::Error;
2use std::fmt::{Debug, Display};
3
4pub struct StrError<'a> {
5 msg: &'a str,
6}
7
8impl<'a> StrError<'a> {
9 pub fn from_str(error: &str) -> Box<StrError> {
10 Box::new(StrError { msg: error })
11 }
12}
13
14impl<'a> Display for StrError<'a> {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 write!(f, "StrError(\"{}\")", self.msg)
17 }
18}
19
20impl<'a> Debug for StrError<'a> {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 f.debug_struct("StrError")
23 .field("Message", &self.msg)
24 .finish()
25 }
26}
27
28impl<'a> Error for StrError<'a> {}