1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use dhall::error::Error as DhallError;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub struct Error(pub(crate) ErrorKind);
#[derive(Debug)]
pub(crate) enum ErrorKind {
Dhall(DhallError),
Deserialize(String),
}
impl From<ErrorKind> for Error {
fn from(kind: ErrorKind) -> Error {
Error(kind)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match &self.0 {
ErrorKind::Dhall(err) => write!(f, "{}", err),
ErrorKind::Deserialize(err) => write!(f, "{}", err),
}
}
}
impl std::error::Error for Error {}
impl serde::de::Error for Error {
fn custom<T>(msg: T) -> Self
where
T: std::fmt::Display,
{
ErrorKind::Deserialize(msg.to_string()).into()
}
}