lincolns/
error.rs

1use std::{error::Error as StdError, fmt, io, str::Utf8Error};
2use yaml_rust::ScanError;
3
4/// Possible errors that may occur while loading content
5#[derive(Debug)]
6pub enum Error {
7    /// Failure to parse content
8    Parse(ScanError),
9    /// Failure to load data
10    Io(io::Error),
11    /// Failure to read data as utf8 text
12    Utf8(Utf8Error),
13}
14
15impl fmt::Display for Error {
16    fn fmt(
17        &self,
18        f: &mut fmt::Formatter<'_>,
19    ) -> std::result::Result<(), fmt::Error> {
20        match self {
21            Error::Parse(ref err) => writeln!(f, "{}", err),
22            Error::Io(ref err) => writeln!(f, "{}", err),
23            Error::Utf8(ref err) => writeln!(f, "{}", err),
24        }
25    }
26}
27
28impl StdError for Error {}
29
30impl From<ScanError> for Error {
31    fn from(err: ScanError) -> Error {
32        Error::Parse(err)
33    }
34}
35
36impl From<io::Error> for Error {
37    fn from(err: io::Error) -> Error {
38        Error::Io(err)
39    }
40}
41
42impl From<Utf8Error> for Error {
43    fn from(err: Utf8Error) -> Error {
44        Error::Utf8(err)
45    }
46}
47
48pub type Result<T> = std::result::Result<T, Error>;