From df37aff014d06302ca615834b6ec9a48ec5f3bfc Mon Sep 17 00:00:00 2001 From: Jeff Burdges Date: Tue, 4 Dec 2018 17:19:36 +0100 Subject: [PATCH 1/2] Add Default for ThreadRng --- src/rngs/thread.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index ff772e3989c..16940ec1e2d 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs @@ -99,6 +99,12 @@ pub fn thread_rng() -> ThreadRng { ThreadRng { rng: THREAD_RNG_KEY.with(|t| t.get()) } } +impl Default for ThreadRng { + fn default() -> ThreadRng { + ::prelude::thread_rng() + } +} + impl RngCore for ThreadRng { #[inline(always)] fn next_u32(&mut self) -> u32 { From 57c54bb19aa916825e9304adf914665b4513477b Mon Sep 17 00:00:00 2001 From: Jeff Burdges Date: Wed, 5 Dec 2018 03:19:16 +0100 Subject: [PATCH 2/2] Requested comment --- src/rngs/thread.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index 16940ec1e2d..be77ddfa99e 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs @@ -87,10 +87,11 @@ thread_local!( } ); -/// Retrieve the lazily-initialized thread-local random number -/// generator, seeded by the system. Intended to be used in method -/// chaining style, e.g. `thread_rng().gen::()`, or cached locally, e.g. -/// `let mut rng = thread_rng();`. +/// Retrieve the lazily-initialized thread-local random number generator, +/// seeded by the system. Intended to be used in method chaining style, +/// e.g. `thread_rng().gen::()`, or cached locally, e.g. +/// `let mut rng = thread_rng();`. Invoked by the `Default` trait, making +/// `ThreadRng::default()` equivelent. /// /// For more information see [`ThreadRng`]. ///