Skip to content

Commit b6e50ee

Browse files
committed
Improve doc on implementing Default
1 parent 628a952 commit b6e50ee

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

rand_core/src/lib.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ pub mod le;
9191
/// It is recommended that implementations also implement:
9292
///
9393
/// - `Debug` with a custom implementation which *does not* print any internal
94-
/// state (at least, [`CryptoRng`]s should not risk leaking state through Debug)
94+
/// state (at least, [`CryptoRng`]s should not risk leaking state through
95+
/// `Debug`).
9596
/// - `Serialize` and `Deserialize` (from Serde), preferably making Serde
96-
/// support optional at the crate level in PRNG libs
97-
/// - `Clone` if, and only if, the clone will have identical output to the
98-
/// original (i.e. all deterministic PRNGs but not external generators)
99-
/// - *never* implement `Copy` (accidental copies may cause repeated values)
100-
/// - also *do not* implement `Default`, but instead implement `SeedableRng`
101-
/// thus allowing use of `rand::NewRng` (which is automatically implemented)
102-
/// - `Eq` and `PartialEq` could be implemented, but are probably not useful
97+
/// support optional at the crate level in PRNG libs.
98+
/// - `Clone`, but only if the clone will have identical output to the original
99+
/// (i.e. be a true clone), or if the clone would be another handle to the
100+
/// same generator.
101+
/// - *never* implement `Copy` (accidental copies may cause repeated values).
102+
/// - *do not* implement `Default` for pseudorandom generators, but instead
103+
/// implement [`SeedableRng`], to guide users towards proper seeding.
104+
/// External / hardware RNGs can choose to implement `Default`.
105+
/// - `Eq` and `PartialEq` could be implemented, but are probably not useful.
103106
///
104107
/// # Example
105108
///

src/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use rand_core::{RngCore, Error, impls};
2929
/// machines, it may block very early in the init process, when the OS CSPRNG
3030
/// has not yet been seeded.
3131
///
32-
/// `OsRng::new()` is guaranteed to be very cheap (after first call), and will
33-
/// never consume more than one file handle per process.
32+
/// `OsRng::new()` is guaranteed to be very cheap (after the first succesful
33+
/// call), and will never consume more than one file handle per process.
3434
///
3535
/// ## Platform sources:
3636
///

0 commit comments

Comments
 (0)