[go: up one dir, main page]

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
use std::ffi::OsString;
use std::fmt::{self, Display};
use std::io;

pub enum Error {
    Io(io::Error),
    Utf8(OsString),
    Empty,
}

pub type Result<T> = std::result::Result<T, Error>;

impl Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        use self::Error::*;

        match self {
            Io(err) => err.fmt(f),
            Utf8(name) => write!(
                f,
                "unsupported non-utf8 file name: {}",
                name.to_string_lossy(),
            ),
            Empty => f.write_str("no source files found"),
        }
    }
}

impl From<io::Error> for Error {
    fn from(err: io::Error) -> Self {
        Error::Io(err)
    }
}