Skip to content

Commit 5d0cb4c

Browse files
committed
Reconstruct io::Error from raw code if possible in From impl
Supplied by newpavlov
1 parent 8f3ff15 commit 5d0cb4c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rand_core/src/error.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ impl std::error::Error for Error {
167167
impl From<Error> for std::io::Error {
168168
#[inline]
169169
fn from(error: Error) -> Self {
170-
std::io::Error::new(std::io::ErrorKind::Other, error)
170+
if let Some(code) = error.raw_os_error() {
171+
std::io::Error::from_raw_os_error(code)
172+
} else {
173+
std::io::Error::new(std::io::ErrorKind::Other, error)
174+
}
171175
}
172176
}
173177

0 commit comments

Comments
 (0)