1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::{error, io};

pub type Error = io::Error;
pub type Result<T> = io::Result<T>;

pub(crate) fn to_error<E>(e: E) -> Error
where
    E: error::Error + Send + Sync + 'static,
{
    Error::new(io::ErrorKind::InvalidData, e)
}

pub(crate) fn invalid_data<A, T>(msg: T) -> Result<A>
where
    T: Into<Option<String>>,
{
    Err(if let Some(msg) = msg.into() {
        Error::new(io::ErrorKind::InvalidData, msg)
    } else {
        io::ErrorKind::InvalidData.into()
    })
}