Skip to content

Commit

Permalink
Reconstruct io::Error from raw code if possible in From impl
Browse files Browse the repository at this point in the history
Supplied by newpavlov
  • Loading branch information
dhardy committed Aug 22, 2019
1 parent 2f9e9b2 commit df0c772
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rand_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ impl std::error::Error for Error {
impl From<Error> for std::io::Error {
#[inline]
fn from(error: Error) -> Self {
std::io::Error::new(std::io::ErrorKind::Other, error)
if let Some(code) = error.raw_os_error() {
std::io::Error::from_raw_os_error(code)
} else {
std::io::Error::new(std::io::ErrorKind::Other, error)
}
}
}

Expand Down

0 comments on commit df0c772

Please sign in to comment.