docker_puzzles/
error.rs

1use std::error::Error;
2
3#[derive(Debug, Clone)]
4pub struct UserError<'a> {
5    message: &'a str,
6}
7
8impl<'a> UserError<'a> {
9    pub fn new(message: &'a str) -> UserError<'a> {
10        UserError { message }
11    }
12
13    pub fn boxed(message: &'a str) -> Box<UserError<'a>> {
14        Box::new(UserError::new(message))
15    }
16}
17
18impl<'a> std::fmt::Display for UserError<'a> {
19    fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
20        write!(formatter, "{}", self.message)
21    }
22}
23
24impl<'a> Error for UserError<'a> {
25    fn description(&self) -> &str {
26        &self.message
27    }
28
29    fn cause(&self) -> Option<&Error> {
30        None
31    }
32}