Skip to content

Commit 42ece4f

Browse files
committed
Document and correct usage of new rand_os "feature"
1 parent 1d97fa1 commit 42ece4f

File tree

5 files changed

+19
-159
lines changed

5 files changed

+19
-159
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ pinned version of Rustc if you require compatibility with a specific version.
7474

7575
## Crate Features
7676

77-
Rand is built with only the `std` feature enabled by default. The following
78-
optional features are available:
77+
Rand is built with the `std` and `rand_os` features enabled by default:
78+
79+
- `std` enables functionality dependent on the `std` lib and implies `alloc`
80+
and `rand_os`
81+
- `rand_os` enables the `rand_os` crate, `rngs::OsRng` and enables its usage;
82+
the continued existance of this feature is not guaranteed so users are
83+
encouraged to specify `std` instead
84+
85+
The following optional features are available:
7986

8087
- `alloc` can be used instead of `std` to provide `Vec` and `Box`.
8188
- `log` enables some logging via the `log` crate.

src/deprecated.rs

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -291,45 +291,12 @@ impl SeedableRng for StdRng {
291291
impl CryptoRng for StdRng {}
292292

293293

294-
#[cfg(all(feature="std",
295-
any(target_os = "linux", target_os = "android",
296-
target_os = "netbsd",
297-
target_os = "dragonfly",
298-
target_os = "haiku",
299-
target_os = "emscripten",
300-
target_os = "solaris",
301-
target_os = "cloudabi",
302-
target_os = "macos", target_os = "ios",
303-
target_os = "freebsd",
304-
target_os = "openbsd", target_os = "bitrig",
305-
target_os = "redox",
306-
target_os = "fuchsia",
307-
windows,
308-
all(target_arch = "wasm32", feature = "stdweb"),
309-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
310-
)))]
294+
#[cfg(feature="rand_os")]
311295
#[derive(Clone, Debug)]
312296
#[deprecated(since="0.6.0", note="import with rand::rngs::OsRng instead")]
313297
pub struct OsRng(rngs::OsRng);
314298

315-
#[cfg(all(feature="std",
316-
any(target_os = "linux", target_os = "android",
317-
target_os = "netbsd",
318-
target_os = "dragonfly",
319-
target_os = "haiku",
320-
target_os = "emscripten",
321-
target_os = "solaris",
322-
target_os = "cloudabi",
323-
target_os = "macos", target_os = "ios",
324-
target_os = "freebsd",
325-
target_os = "openbsd", target_os = "bitrig",
326-
target_os = "redox",
327-
target_os = "fuchsia",
328-
windows,
329-
all(target_arch = "wasm32", feature = "stdweb"),
330-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
331-
)))]
332-
#[cfg(feature="std")]
299+
#[cfg(feature="rand_os")]
333300
impl RngCore for OsRng {
334301
#[inline(always)]
335302
fn next_u32(&mut self) -> u32 {
@@ -352,48 +319,14 @@ impl RngCore for OsRng {
352319
}
353320
}
354321

355-
#[cfg(all(feature="std",
356-
any(target_os = "linux", target_os = "android",
357-
target_os = "netbsd",
358-
target_os = "dragonfly",
359-
target_os = "haiku",
360-
target_os = "emscripten",
361-
target_os = "solaris",
362-
target_os = "cloudabi",
363-
target_os = "macos", target_os = "ios",
364-
target_os = "freebsd",
365-
target_os = "openbsd", target_os = "bitrig",
366-
target_os = "redox",
367-
target_os = "fuchsia",
368-
windows,
369-
all(target_arch = "wasm32", feature = "stdweb"),
370-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
371-
)))]
372-
#[cfg(feature="std")]
322+
#[cfg(feature="rand_os")]
373323
impl OsRng {
374324
pub fn new() -> Result<Self, Error> {
375325
rngs::OsRng::new().map(OsRng)
376326
}
377327
}
378328

379-
#[cfg(all(feature="std",
380-
any(target_os = "linux", target_os = "android",
381-
target_os = "netbsd",
382-
target_os = "dragonfly",
383-
target_os = "haiku",
384-
target_os = "emscripten",
385-
target_os = "solaris",
386-
target_os = "cloudabi",
387-
target_os = "macos", target_os = "ios",
388-
target_os = "freebsd",
389-
target_os = "openbsd", target_os = "bitrig",
390-
target_os = "redox",
391-
target_os = "fuchsia",
392-
windows,
393-
all(target_arch = "wasm32", feature = "stdweb"),
394-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
395-
)))]
396-
#[cfg(feature="std")]
329+
#[cfg(feature="rand_os")]
397330
impl CryptoRng for OsRng {}
398331

399332

src/lib.rs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,7 @@ pub mod seq;
119119
#[cfg(feature="std")] #[doc(hidden)] pub use deprecated::EntropyRng;
120120

121121
#[allow(deprecated)]
122-
#[cfg(all(feature="std",
123-
any(target_os = "linux", target_os = "android",
124-
target_os = "netbsd",
125-
target_os = "dragonfly",
126-
target_os = "haiku",
127-
target_os = "emscripten",
128-
target_os = "solaris",
129-
target_os = "cloudabi",
130-
target_os = "macos", target_os = "ios",
131-
target_os = "freebsd",
132-
target_os = "openbsd", target_os = "bitrig",
133-
target_os = "redox",
134-
target_os = "fuchsia",
135-
windows,
136-
all(target_arch = "wasm32", feature = "stdweb"),
137-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
138-
)))]
122+
#[cfg(feature="rand_os")]
139123
#[doc(hidden)]
140124
pub use deprecated::OsRng;
141125

@@ -152,23 +136,7 @@ pub mod jitter {
152136
pub use rngs::TimerError;
153137
}
154138
#[allow(deprecated)]
155-
#[cfg(all(feature="std",
156-
any(target_os = "linux", target_os = "android",
157-
target_os = "netbsd",
158-
target_os = "dragonfly",
159-
target_os = "haiku",
160-
target_os = "emscripten",
161-
target_os = "solaris",
162-
target_os = "cloudabi",
163-
target_os = "macos", target_os = "ios",
164-
target_os = "freebsd",
165-
target_os = "openbsd", target_os = "bitrig",
166-
target_os = "redox",
167-
target_os = "fuchsia",
168-
windows,
169-
all(target_arch = "wasm32", feature = "stdweb"),
170-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
171-
)))]
139+
#[cfg(feature="rand_os")]
172140
#[doc(hidden)]
173141
pub mod os {
174142
pub use deprecated::OsRng;

src/rngs/entropy.rs

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -191,43 +191,11 @@ impl EntropySource for NoSource {
191191
}
192192

193193

194-
#[cfg(all(feature="std",
195-
any(target_os = "linux", target_os = "android",
196-
target_os = "netbsd",
197-
target_os = "dragonfly",
198-
target_os = "haiku",
199-
target_os = "emscripten",
200-
target_os = "solaris",
201-
target_os = "cloudabi",
202-
target_os = "macos", target_os = "ios",
203-
target_os = "freebsd",
204-
target_os = "openbsd", target_os = "bitrig",
205-
target_os = "redox",
206-
target_os = "fuchsia",
207-
windows,
208-
all(target_arch = "wasm32", feature = "stdweb"),
209-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
210-
)))]
194+
#[cfg(feature="rand_os")]
211195
#[derive(Clone, Debug)]
212196
pub struct Os(rngs::OsRng);
213197

214-
#[cfg(all(feature="std",
215-
any(target_os = "linux", target_os = "android",
216-
target_os = "netbsd",
217-
target_os = "dragonfly",
218-
target_os = "haiku",
219-
target_os = "emscripten",
220-
target_os = "solaris",
221-
target_os = "cloudabi",
222-
target_os = "macos", target_os = "ios",
223-
target_os = "freebsd",
224-
target_os = "openbsd", target_os = "bitrig",
225-
target_os = "redox",
226-
target_os = "fuchsia",
227-
windows,
228-
all(target_arch = "wasm32", feature = "stdweb"),
229-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
230-
)))]
198+
#[cfg(feature="rand_os")]
231199
impl EntropySource for Os {
232200
fn new_and_fill(dest: &mut [u8]) -> Result<Self, Error> {
233201
let mut rng = rngs::OsRng::new()?;
@@ -240,23 +208,7 @@ impl EntropySource for Os {
240208
}
241209
}
242210

243-
#[cfg(not(all(feature="std",
244-
any(target_os = "linux", target_os = "android",
245-
target_os = "netbsd",
246-
target_os = "dragonfly",
247-
target_os = "haiku",
248-
target_os = "emscripten",
249-
target_os = "solaris",
250-
target_os = "cloudabi",
251-
target_os = "macos", target_os = "ios",
252-
target_os = "freebsd",
253-
target_os = "openbsd", target_os = "bitrig",
254-
target_os = "redox",
255-
target_os = "fuchsia",
256-
windows,
257-
all(target_arch = "wasm32", feature = "stdweb"),
258-
all(target_arch = "wasm32", feature = "wasm-bindgen"),
259-
))))]
211+
#[cfg(not(feature="std"))]
260212
type Os = NoSource;
261213

262214

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(feature="std")]
181+
#[cfg(feature="rand_os")]
182182
pub use rand_os::OsRng;

0 commit comments

Comments
 (0)