From 62fededd8e9cfd85197f224123a057df43a6feab Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 9 Oct 2013 09:56:57 +1100 Subject: [PATCH] std::rand: Make Rng.next_u32 non-default, waiting for #7771. --- src/libstd/rand/isaac.rs | 6 ++++++ src/libstd/rand/mod.rs | 8 ++------ src/libstd/rand/rand_impls.rs | 3 +++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libstd/rand/isaac.rs b/src/libstd/rand/isaac.rs index b785189ef937..0068b60cfa51 100644 --- a/src/libstd/rand/isaac.rs +++ b/src/libstd/rand/isaac.rs @@ -363,6 +363,12 @@ impl Isaac64Rng { } impl Rng for Isaac64Rng { + // FIXME #7771: having next_u32 like this should be unnecessary + #[inline] + fn next_u32(&mut self) -> u32 { + self.next_u64() as u32 + } + #[inline] fn next_u64(&mut self) -> u64 { if self.cnt == 0 { diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index f68bf71ba7f5..a6ffbdd7b17d 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -99,12 +99,8 @@ pub trait Rng { /// Return the next random u32. This rarely needs to be called /// directly, prefer `r.gen()` to `r.next_u32()`. /// - /// By default this is implemented in terms of `next_u64`. An - /// implementation of this trait must provide at least one of - /// these two methods. - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } + // FIXME #7771: Should be implemented in terms of next_u64 + fn next_u32(&mut self) -> u32; /// Return the next random u64. This rarely needs to be called /// directly, prefer `r.gen()` to `r.next_u64()`. diff --git a/src/libstd/rand/rand_impls.rs b/src/libstd/rand/rand_impls.rs index 8ad0bd9e2975..aad0d4e861c5 100644 --- a/src/libstd/rand/rand_impls.rs +++ b/src/libstd/rand/rand_impls.rs @@ -209,6 +209,9 @@ mod tests { use rand::Rng; struct ConstantRng(u64); impl Rng for ConstantRng { + fn next_u32(&mut self) -> u32 { + (**self) as u32 + } fn next_u64(&mut self) -> u64 { **self }