Skip to content

Commit

Permalink
Document and correct usage of new rand_os "feature"
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jan 8, 2019
1 parent 1d97fa1 commit 42ece4f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 159 deletions.
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -74,8 +74,15 @@ pinned version of Rustc if you require compatibility with a specific version.

## Crate Features

Rand is built with only the `std` feature enabled by default. The following
optional features are available:
Rand is built with the `std` and `rand_os` features enabled by default:

- `std` enables functionality dependent on the `std` lib and implies `alloc`
and `rand_os`
- `rand_os` enables the `rand_os` crate, `rngs::OsRng` and enables its usage;
the continued existance of this feature is not guaranteed so users are
encouraged to specify `std` instead

The following optional features are available:

- `alloc` can be used instead of `std` to provide `Vec` and `Box`.
- `log` enables some logging via the `log` crate.
Expand Down
75 changes: 4 additions & 71 deletions src/deprecated.rs
Expand Up @@ -291,45 +291,12 @@ impl SeedableRng for StdRng {
impl CryptoRng for StdRng {}


#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="rand_os")]
#[derive(Clone, Debug)]
#[deprecated(since="0.6.0", note="import with rand::rngs::OsRng instead")]
pub struct OsRng(rngs::OsRng);

#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="std")]
#[cfg(feature="rand_os")]
impl RngCore for OsRng {
#[inline(always)]
fn next_u32(&mut self) -> u32 {
Expand All @@ -352,48 +319,14 @@ impl RngCore for OsRng {
}
}

#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="std")]
#[cfg(feature="rand_os")]
impl OsRng {
pub fn new() -> Result<Self, Error> {
rngs::OsRng::new().map(OsRng)
}
}

#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="std")]
#[cfg(feature="rand_os")]
impl CryptoRng for OsRng {}


Expand Down
36 changes: 2 additions & 34 deletions src/lib.rs
Expand Up @@ -119,23 +119,7 @@ pub mod seq;
#[cfg(feature="std")] #[doc(hidden)] pub use deprecated::EntropyRng;

#[allow(deprecated)]
#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="rand_os")]
#[doc(hidden)]
pub use deprecated::OsRng;

Expand All @@ -152,23 +136,7 @@ pub mod jitter {
pub use rngs::TimerError;
}
#[allow(deprecated)]
#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="rand_os")]
#[doc(hidden)]
pub mod os {
pub use deprecated::OsRng;
Expand Down
54 changes: 3 additions & 51 deletions src/rngs/entropy.rs
Expand Up @@ -191,43 +191,11 @@ impl EntropySource for NoSource {
}


#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="rand_os")]
#[derive(Clone, Debug)]
pub struct Os(rngs::OsRng);

#[cfg(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)))]
#[cfg(feature="rand_os")]
impl EntropySource for Os {
fn new_and_fill(dest: &mut [u8]) -> Result<Self, Error> {
let mut rng = rngs::OsRng::new()?;
Expand All @@ -240,23 +208,7 @@ impl EntropySource for Os {
}
}

#[cfg(not(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
))))]
#[cfg(not(feature="std"))]
type Os = NoSource;


Expand Down
2 changes: 1 addition & 1 deletion src/rngs/mod.rs
Expand Up @@ -178,5 +178,5 @@ pub use self::small::SmallRng;
pub use self::std::StdRng;
#[cfg(feature="std")] pub use self::thread::ThreadRng;

#[cfg(feature="std")]
#[cfg(feature="rand_os")]
pub use rand_os::OsRng;

0 comments on commit 42ece4f

Please sign in to comment.