Skip to main content

bake/
error.rs

1use std::fmt;
2
3/// An actionable task, argument, registration, or process error.
4#[derive(Debug)]
5pub struct Error {
6    message: String,
7}
8
9impl Error {
10    pub fn new(message: impl Into<String>) -> Self {
11        Self {
12            message: message.into(),
13        }
14    }
15}
16
17impl fmt::Display for Error {
18    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
19        formatter.write_str(&self.message)
20    }
21}
22
23impl std::error::Error for Error {}
24
25impl From<std::io::Error> for Error {
26    fn from(error: std::io::Error) -> Self {
27        Self::new(error.to_string())
28    }
29}
30
31impl From<serde_json::Error> for Error {
32    fn from(error: serde_json::Error) -> Self {
33        Self::new(error.to_string())
34    }
35}
36
37pub type Result<Output = ()> = std::result::Result<Output, Error>;