ligen_common/
error.rs

1//! Error types.
2
3/// Library error.
4#[derive(Debug)]
5pub enum Error {
6    /// IO errors.
7    IO(std::io::Error),
8    /// JSON errors.
9    JSON(serde_json::Error),
10    /// Environment errors.
11    Environment(std::env::VarError),
12    /// Misc errors.
13    Message(String),
14    /// Generic.
15    Generic(Box<dyn std::error::Error>)
16}
17
18impl From<&str> for Error {
19    fn from(s: &str) -> Self {
20        Self::Message(s.into())
21    }
22}
23
24impl From<String> for Error {
25    fn from(s: String) -> Self {
26        Self::Message(s)
27    }
28}
29
30impl From<std::io::Error> for Error {
31    fn from(error: std::io::Error) -> Self {
32        Self::IO(error)
33    }
34}
35
36impl From<serde_json::Error> for Error {
37    fn from(error: serde_json::Error) -> Self {
38        Self::JSON(error)
39    }
40}
41
42impl From<std::env::VarError> for Error {
43    fn from(error: std::env::VarError) -> Self {
44        Self::Environment(error)
45    }
46}
47
48/// Library result.
49pub type Result<T> = std::result::Result<T, Error>;