From 2b87a338eb67567f834ce0ef71faf16e6f851a23 Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Wed, 1 May 2024 19:07:38 +0000 Subject: [PATCH] Add conversion to io::Error --- CHANGELOG.md | 1 + src/error.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) 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), + } + } +}