Skip to content

Commit 7e93a69

Browse files
authored
Merge pull request #15 from newpavlov/edition
MSRV bump, module changes
2 parents 19c39fb + 5e23e13 commit 7e93a69

24 files changed

+220
-313
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ sudo: false
33

44
matrix:
55
include:
6-
- rust: 1.28.0
7-
env: DESCRIPTION="Linux, 1.28.0"
6+
- rust: 1.32.0
7+
env: DESCRIPTION="Linux, 1.32.0"
88
os: linux
99

10-
- rust: 1.28.0
11-
env: DESCRIPTION="OSX, 1.22.0"
10+
- rust: 1.32.0
11+
env: DESCRIPTION="OSX, 1.32.0"
1212
os: osx
1313

1414
- rust: stable
@@ -123,7 +123,7 @@ matrix:
123123
- source ~/.cargo/env || true
124124
script:
125125
- bash utils/ci/script.sh
126-
126+
127127
- rust: stable
128128
sudo: required
129129
dist: trusty

Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "getrandom"
33
version = "0.1.0"
4+
edition = "2018"
45
authors = ["The Rand Project Developers"]
56
license = "MIT OR Apache-2.0"
67
description = "A small cross-platform library for retrieving random data from system source"
@@ -14,9 +15,7 @@ travis-ci = { repository = "rust-random/getrandom" }
1415
appveyor = { repository = "rust-random/getrandom" }
1516

1617
[workspace]
17-
members = [
18-
"tests/wasm_bindgen",
19-
]
18+
members = ["tests/wasm_bindgen"]
2019

2120
[dependencies]
2221
log = { version = "0.4", optional = true }
@@ -36,3 +35,6 @@ fuchsia-cprng = "0.1"
3635
[target.wasm32-unknown-unknown.dependencies]
3736
wasm-bindgen = { version = "0.2.29", optional = true }
3837
stdweb = { version = "0.4.9", optional = true }
38+
39+
[features]
40+
std = []

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ the same set of platforms as Rust's `std` lib.
1616
This is a low-level API. Most users should prefer using high-level random-number
1717
library like [`rand`].
1818

19-
[Rand]: https://crates.io/crates/rand
19+
[`rand`]: https://crates.io/crates/rand
2020

2121

2222
## Usage
@@ -53,7 +53,7 @@ one of the following features must be enabled:
5353

5454
## Minimum Supported Rust Version
5555

56-
This crate requires Rustc version 1.28.0 or later due to usage of `NonZeroU32`.
56+
This crate requires Rust 1.32.0 or later.
5757

5858

5959
# License

src/cloudabi.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
// except according to those terms.
88

99
//! Implementation for CloudABI
10-
11-
extern crate cloudabi;
12-
1310
use core::num::NonZeroU32;
14-
use Error;
11+
use crate::Error;
1512

1613
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1714
let errno = unsafe { cloudabi::random_get(dest) };

src/dragonfly_haiku.rs

-29
This file was deleted.

src/dummy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
//! A dummy implementation for unsupported targets which always returns
1010
//! `Err(Error::UNAVAILABLE)`
11-
use std::num::NonZeroU32;
12-
use Error;
11+
use core::num::NonZeroU32;
12+
use crate::Error;
1313

1414
pub fn getrandom_inner(_: &mut [u8]) -> Result<(), Error> {
1515
error!("no support for this platform");

src/emscripten.rs

-35
This file was deleted.

src/error.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
8-
98
use core::num::NonZeroU32;
109
use core::convert::From;
1110
use core::fmt;
12-
#[cfg(not(target_env = "sgx"))]
13-
use std::{io, error};
1411

1512
// A randomly-chosen 24-bit prefix for our codes
1613
pub(crate) const CODE_PREFIX: u32 = 0x57f4c500;
@@ -21,7 +18,7 @@ const CODE_UNAVAILABLE: u32 = CODE_PREFIX | 0x01;
2118
///
2219
/// This type is small and no-std compatible.
2320
#[derive(Copy, Clone, Eq, PartialEq)]
24-
pub struct Error(NonZeroU32);
21+
pub struct Error(pub(crate) NonZeroU32);
2522

2623
impl Error {
2724
/// An unknown error.
@@ -44,7 +41,7 @@ impl Error {
4441
self.0
4542
}
4643

47-
fn msg(&self) -> Option<&'static str> {
44+
pub(crate) fn msg(&self) -> Option<&'static str> {
4845
if let Some(msg) = super::error_msg_inner(self.0) {
4946
Some(msg)
5047
} else {
@@ -81,33 +78,9 @@ impl From<NonZeroU32> for Error {
8178
}
8279
}
8380

84-
#[cfg(not(target_env = "sgx"))]
85-
impl From<io::Error> for Error {
86-
fn from(err: io::Error) -> Self {
87-
err.raw_os_error()
88-
.and_then(|code| NonZeroU32::new(code as u32))
89-
.map(|code| Error(code))
90-
// in practice this should never happen
91-
.unwrap_or(Error::UNKNOWN)
92-
}
93-
}
94-
95-
#[cfg(not(target_env = "sgx"))]
96-
impl From<Error> for io::Error {
97-
fn from(err: Error) -> Self {
98-
match err.msg() {
99-
Some(msg) => io::Error::new(io::ErrorKind::Other, msg),
100-
None => io::Error::from_raw_os_error(err.0.get() as i32),
101-
}
102-
}
103-
}
104-
105-
#[cfg(not(target_env = "sgx"))]
106-
impl error::Error for Error { }
107-
10881
#[cfg(test)]
10982
mod tests {
110-
use std::mem::size_of;
83+
use core::mem::size_of;
11184
use super::Error;
11285

11386
#[test]

src/error_impls.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 std::{io, error};
11+
use core::convert::From;
12+
use core::num::NonZeroU32;
13+
use crate::error::Error;
14+
15+
impl From<io::Error> for Error {
16+
fn from(err: io::Error) -> Self {
17+
err.raw_os_error()
18+
.and_then(|code| NonZeroU32::new(code as u32))
19+
.map(|code| Error(code))
20+
// in practice this should never happen
21+
.unwrap_or(Error::UNKNOWN)
22+
}
23+
}
24+
25+
impl From<Error> for io::Error {
26+
fn from(err: Error) -> Self {
27+
match err.msg() {
28+
Some(msg) => io::Error::new(io::ErrorKind::Other, msg),
29+
None => io::Error::from_raw_os_error(err.0.get() as i32),
30+
}
31+
}
32+
}
33+
34+
impl error::Error for Error { }

src/freebsd.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// except according to those terms.
88

99
//! Implementation for FreeBSD
10-
extern crate libc;
10+
extern crate std;
1111

12-
use Error;
13-
use core::ptr;
12+
use crate::Error;
1413
use std::io;
15-
use std::num::NonZeroU32;
14+
use core::ptr;
15+
use core::num::NonZeroU32;
1616

1717
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1818
let mib = [libc::CTL_KERN, libc::KERN_ARND];

src/fuchsia.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
// except according to those terms.
88

99
//! Implementation for Fuchsia Zircon
10-
extern crate fuchsia_cprng;
11-
12-
use std::num::NonZeroU32;
13-
use Error;
10+
use core::num::NonZeroU32;
11+
use crate::Error;
1412

1513
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1614
fuchsia_cprng::cprng_draw(dest);

0 commit comments

Comments
 (0)