Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trait implementation guidance #312

Merged
merged 2 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rand-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ pub mod le;
/// in this trait directly, then use the helper functions from the [`impls`]
/// module to implement the other methods.
///
/// It is recommended that implementations also implement:
///
/// - `Debug` with a custom implementation which *does not* print any internal
/// state (at least, `CryptoRng`s should not risk leaking state through Debug)
/// - `Serialize` and `Deserialize` (from Serde), preferably making Serde
/// support optional at the crate level in PRNG libs
/// - `Clone` if, and only if, the clone will have identical output to the
/// original (i.e. all deterministic PRNGs but not external generators)
/// - *never* implement `Copy` (accidental copies may cause repeated values)
/// - also *do not* implement `Default`, but instead implement `SeedableRng`
/// thus allowing use of `rand::NewRng` (which is automatically implemented)
/// - `Eq` and `PartialEq` could be implemented, but are probably not useful
///
/// # Example
///
/// A simple example, obviously not generating very *random* output:
Expand Down
3 changes: 2 additions & 1 deletion src/thread_rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ use reseeding::ReseedingRng;
const THREAD_RNG_RESEED_THRESHOLD: u64 = 32*1024*1024; // 32 MiB

/// The type returned by [`thread_rng`], essentially just a reference to the
/// PRNG in thread-local memory.
/// PRNG in thread-local memory. Cloning this handle just produces a new
/// reference to the same thread-local generator.
///
/// [`thread_rng`]: fn.thread_rng.html
#[derive(Clone, Debug)]
Expand Down