use std::io;
use crate::*;
pub fn new_std_io_error(err: io::Error) -> Error {
use std::io::ErrorKind::*;
let (kind, retryable) = match err.kind() {
NotFound => (ErrorKind::NotFound, false),
PermissionDenied => (ErrorKind::PermissionDenied, false),
AlreadyExists => (ErrorKind::AlreadyExists, false),
Unsupported => (ErrorKind::Unsupported, false),
Interrupted | UnexpectedEof | TimedOut | WouldBlock => (ErrorKind::Unexpected, true),
_ => (ErrorKind::Unexpected, true),
};
let mut err = Error::new(kind, err.kind().to_string()).set_source(err);
if retryable {
err = err.set_temporary();
}
err
}
#[inline]
pub(crate) fn format_std_io_error(err: Error) -> io::Error {
let kind = match err.kind() {
ErrorKind::NotFound => io::ErrorKind::NotFound,
ErrorKind::PermissionDenied => io::ErrorKind::PermissionDenied,
_ => io::ErrorKind::Interrupted,
};
io::Error::new(kind, err)
}