]> git.proxmox.com Git - rustc.git/blame - vendor/getrandom/src/error_impls.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / vendor / getrandom / src / error_impls.rs
CommitLineData
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.
8extern crate std;
9
10use crate::{error::UNKNOWN_IO_ERROR, Error};
11use core::convert::From;
12use core::num::NonZeroU32;
13use std::io;
14
15impl 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
26impl 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
35impl std::error::Error for Error {}