Skip to content

Commit 3c01310

Browse files
committed
Add conversion to io::Error
1 parent 709bd24 commit 3c01310

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [master] - Unreleased
44

5+
### Changed
6+
7+
- The crate's `Error` type can now be converted to a `std::io::Error` using `From` / `Into`.
8+
59
## [0.6.1] - 2021-11-22
610

711
### Changed

src/error.rs

+11
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ impl convert::From<nix::Error> for Error {
4545
Error::Io(e.into())
4646
}
4747
}
48+
49+
impl convert::From<Error> for io::Error {
50+
fn from(e: Error) -> io::Error {
51+
match e {
52+
Error::Io(err) => err,
53+
Error::Unexpected(err) => io::Error::new(io::ErrorKind::Unsupported, err),
54+
Error::InvalidPath(err) => io::Error::new(io::ErrorKind::InvalidInput, err),
55+
Error::Unsupported(err) => io::Error::new(io::ErrorKind::InvalidData, err),
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)