Skip to content

Commit

Permalink
std::rand: Make Rng.next_u32 non-default, waiting for rust-lang#7771.
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed Oct 9, 2013
1 parent 618c6af commit 62feded
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/libstd/rand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions src/libstd/rand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/rand/rand_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 62feded

Please sign in to comment.