summaryrefslogtreecommitdiff
path: root/src/errors.rs
blob: bfb5606f2807db779f7e5b1c4bcc7e5bf42b0753 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::io;

pub trait ToIOError {
    fn to_io_error(self) -> io::Error;
}

impl ToIOError for git2::Error {
    fn to_io_error(self) -> io::Error {
        io::Error::new(io::ErrorKind::Other, self)
    }
}

pub trait ToIOResult<T> {
    fn to_io_result(self) -> io::Result<T>;
}

impl<T, E: ToIOError> ToIOResult<T> for std::result::Result<T, E> {
    fn to_io_result(self) -> io::Result<T> {
        self.map_err(|e| e.to_io_error())
    }
}