]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // Copyright 2018 Developers of the Rand project. |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
4 | // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
5 | // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | |
6 | // option. This file may not be copied, modified, or distributed | |
7 | // except according to those terms. | |
8 | extern crate std; | |
9 | ||
10 | use crate::{error::UNKNOWN_IO_ERROR, Error}; | |
11 | use core::convert::From; | |
12 | use core::num::NonZeroU32; | |
13 | use std::io; | |
14 | ||
15 | impl From<io::Error> for Error { | |
16 | fn from(err: io::Error) -> Self { | |
17 | if let Some(errno) = err.raw_os_error() { | |
18 | if let Some(code) = NonZeroU32::new(errno as u32) { | |
19 | return Error::from(code); | |
20 | } | |
21 | } | |
22 | UNKNOWN_IO_ERROR | |
23 | } | |
24 | } | |
25 | ||
26 | impl From<Error> for io::Error { | |
27 | fn from(err: Error) -> Self { | |
28 | match err.raw_os_error() { | |
29 | Some(errno) => io::Error::from_raw_os_error(errno), | |
30 | None => io::Error::new(io::ErrorKind::Other, err), | |
31 | } | |
32 | } | |
33 | } | |
34 | ||
35 | impl std::error::Error for Error {} |