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
41
42
43
44
45
46
47
48
use std::{error::Error as StdError, fmt, io, str::Utf8Error};
use yaml_rust::ScanError;
#[derive(Debug)]
pub enum Error {
Parse(ScanError),
Io(io::Error),
Utf8(Utf8Error),
}
impl fmt::Display for Error {
fn fmt(
&self,
f: &mut fmt::Formatter<'_>,
) -> std::result::Result<(), fmt::Error> {
match self {
Error::Parse(ref err) => writeln!(f, "{}", err),
Error::Io(ref err) => writeln!(f, "{}", err),
Error::Utf8(ref err) => writeln!(f, "{}", err),
}
}
}
impl StdError for Error {}
impl From<ScanError> for Error {
fn from(err: ScanError) -> Error {
Error::Parse(err)
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Io(err)
}
}
impl From<Utf8Error> for Error {
fn from(err: Utf8Error) -> Error {
Error::Utf8(err)
}
}
pub type Result<T> = std::result::Result<T, Error>;