1pub use serde_json as json;
2pub use serde_yaml as yaml;
3use std::fmt::Display;
4use std::io;
5
6#[derive(Debug)]
7pub enum Error {
8 Json(json::Error),
9 Yaml(yaml::Error),
10 Jf(String),
11 Io(io::Error),
12}
13
14impl Error {
15 pub fn returncode(&self) -> i32 {
16 match self {
17 Self::Jf(_) => 1,
18 Self::Json(_) => 2,
19 Self::Yaml(_) => 3,
20 Self::Io(_) => 4,
21 }
22 }
23}
24
25impl From<yaml::Error> for Error {
26 fn from(v: yaml::Error) -> Self {
27 Self::Yaml(v)
28 }
29}
30
31impl From<json::Error> for Error {
32 fn from(v: json::Error) -> Self {
33 Self::Json(v)
34 }
35}
36
37impl From<&str> for Error {
38 fn from(v: &str) -> Self {
39 Self::Jf(v.to_string())
40 }
41}
42
43impl From<io::Error> for Error {
44 fn from(v: io::Error) -> Self {
45 Self::Io(v)
46 }
47}
48
49impl Display for Error {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 match self {
52 Self::Json(e) => write!(f, "json: {e}"),
53 Self::Yaml(e) => write!(f, "yaml: {e}"),
54 Self::Jf(e) => write!(f, "jf: {e}"),
55 Self::Io(e) => write!(f, "io: {e}"),
56 }
57 }
58}
59
60pub type Result<T> = std::result::Result<T, Error>;