Skip to content

Commit bddd20d

Browse files
authored
Merge pull request #1 from dhardy/rand_os
rand_os: doc and cargo improvements
2 parents a57925a + 808cd54 commit bddd20d

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

Cargo.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ simd_support = ["packed_simd"] # enables SIMD support
2929
serde1 = ["rand_core/serde1", "rand_isaac/serde1", "rand_xorshift/serde1"] # enables serialization for PRNGs
3030

3131
[workspace]
32-
members = ["rand_core", "rand_os", "rand_isaac", "rand_chacha", "rand_hc", "rand_pcg", "rand_xorshift"]
32+
members = [
33+
"rand_core",
34+
"rand_os",
35+
"rand_isaac",
36+
"rand_chacha",
37+
"rand_hc",
38+
"rand_pcg",
39+
"rand_xorshift",
40+
"rand_xoshiro",
41+
]
3342

3443
[dependencies]
3544
rand_core = { path = "rand_core", version = "0.3", default-features = false }
@@ -51,7 +60,7 @@ optional = true
5160
features = ["into_bits"]
5261

5362
[target.'cfg(unix)'.dependencies]
54-
libc = "0.2"
63+
libc = { version = "0.2", default-features = false }
5564

5665
# TODO: check if all features are required
5766
[target.'cfg(windows)'.dependencies]

rand_os/LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Copyright (c) 2014-2017 Melissa O'Neill and PCG Project contributors
21
Copyright 2018 Developers of the Rand project
2+
Copyright (c) 2014 The Rust Project Developers
33

44
Permission is hereby granted, free of charge, to any
55
person obtaining a copy of this software and associated

rand_os/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ operating system.
1313
This crate depends on [rand_core](https://crates.io/crates/rand_core) and is
1414
part of the [Rand project](https://github.com/rust-random/rand).
1515

16+
This crate aims to support all of Rust's `std` platforms with a system-provided
17+
entropy source. Unlike other Rand crates, this crate does not support `no_std`
18+
(handling this gracefully is a current discussion topic).
19+
1620
Documentation:
1721
[master branch](https://rust-random.github.io/rand/rand_os/index.html),
1822
[by release](https://docs.rs/rand_os)

rand_os/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
//! `wasm32-unknown-emscripten` and `wasm32-experimental-emscripten` use
6262
//! Emscripten's emulation of `/dev/random` on web browsers and Node.js.
6363
//!
64-
//! The bare Wasm target `wasm32-unknown-unknown` tries to call the javascript
64+
//! The bare WASM target `wasm32-unknown-unknown` tries to call the javascript
6565
//! methods directly, using either `stdweb` or `wasm-bindgen` depending on what
6666
//! features are activated for this crate. Note that if both features are
6767
//! enabled `wasm-bindgen` will be used.
@@ -87,12 +87,17 @@
8787
//! `/dev/random` until we know the OS RNG is initialized (and store this in a
8888
//! global static).
8989
//!
90-
//! # Panics
90+
//! # Panics and error handling
9191
//!
92-
//! `OsRng` is extremely unlikely to fail if `OsRng::new()`, and one read from
93-
//! it, where succesfull. But in case it does fail, only [`try_fill_bytes`] is
94-
//! able to report the cause. Depending on the error the other [`RngCore`]
95-
//! methods will retry several times, and panic in case the error remains.
92+
//! We cannot guarantee that `OsRng` will fail, but if it does, it will likely
93+
//! be either when `OsRng::new()` is first called or when data is first read.
94+
//! If you wish to catch errors early, then test reading of at least one byte
95+
//! from `OsRng` via [`try_fill_bytes`]. If this succeeds, it is extremely
96+
//! unlikely that any further errors will occur.
97+
//!
98+
//! Only [`try_fill_bytes`] is able to report the cause of an error; the other
99+
//! [`RngCore`] methods may (depending on the error kind) retry several times,
100+
//! but must eventually panic if the error persists.
96101
//!
97102
//! [`EntropyRng`]: ../rand/rngs/struct.EntropyRng.html
98103
//! [`RngCore`]: ../rand_core/trait.RngCore.html

src/rngs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,5 @@ pub use self::small::SmallRng;
178178
pub use self::std::StdRng;
179179
#[cfg(feature="std")] pub use self::thread::ThreadRng;
180180

181-
#[cfg(all(feature="std", feature="rand_os"))]
181+
#[cfg(feature="std")]
182182
pub use rand_os::OsRng;

utils/ci/script.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ main() {
1515
cross test --target $TARGET --manifest-path rand_xoshiro/Cargo.toml
1616
cross test --target $TARGET --manifest-path rand_chacha/Cargo.toml
1717
cross test --target $TARGET --manifest-path rand_hc/Cargo.toml
18+
cross test --target $TARGET --manifest-path rand_os/Cargo.toml
1819
}
1920

2021
# we don't run the "test phase" when doing deploys

0 commit comments

Comments
 (0)