diff --git a/CHANGELOG.md b/CHANGELOG.md index f6e3b985d..93ddfbf92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changed - Minimum supported Rust version updated to 1.65.0 +- The crate's `Error` type can now be converted to a `std::io::Error` using `From` / `Into`. ## [0.6.1] - 2021-11-22 diff --git a/src/error.rs b/src/error.rs index a2b7db441..c01c39fa4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -45,3 +45,14 @@ impl convert::From for Error { Error::Io(e.into()) } } + +impl convert::From for io::Error { + fn from(e: Error) -> io::Error { + match e { + Error::Io(err) => err, + Error::Unexpected(err) => io::Error::new(io::ErrorKind::Unsupported, err), + Error::InvalidPath(err) => io::Error::new(io::ErrorKind::InvalidInput, err), + Error::Unsupported(err) => io::Error::new(io::ErrorKind::InvalidData, err), + } + } +}