Skip to main content

heft_format/
error.rs

1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, HeftError>;
4
5#[derive(Debug)]
6pub enum HeftError {
7    Io(std::io::Error),
8    Json(serde_json::Error),
9    Other(String),
10}
11
12impl fmt::Display for HeftError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            HeftError::Io(e) => write!(f, "IO error: {e}"),
16            HeftError::Json(e) => write!(f, "JSON error: {e}"),
17            HeftError::Other(msg) => write!(f, "{msg}"),
18        }
19    }
20}
21
22impl std::error::Error for HeftError {}
23
24impl From<std::io::Error> for HeftError {
25    fn from(e: std::io::Error) -> Self {
26        HeftError::Io(e)
27    }
28}
29
30impl From<serde_json::Error> for HeftError {
31    fn from(e: serde_json::Error) -> Self {
32        HeftError::Json(e)
33    }
34}