Skip to content

Commit

Permalink
Make SampleRng extension trait require Sized
Browse files Browse the repository at this point in the history
All methods already require the bound
  • Loading branch information
dhardy committed Feb 18, 2018
1 parent dfbdddf commit 0a7d935
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ pub trait RngCore {
/// (converting that randomness to the desired type and distribution).
///
/// [`RngCore`]: trait.RngCore.html
pub trait Rng: RngCore {
pub trait Rng: RngCore + Sized {
/// Return a random value of a `Rand` type.
///
/// # Example
Expand All @@ -526,7 +526,7 @@ pub trait Rng: RngCore {
/// println!("{:?}", rng.gen::<(f64, bool)>());
/// ```
#[inline(always)]
fn gen<T: Rand>(&mut self) -> T where Self: Sized {
fn gen<T: Rand>(&mut self) -> T {
Rand::rand(self)
}

Expand All @@ -544,7 +544,7 @@ pub trait Rng: RngCore {
/// println!("{:?}", rng.gen_iter::<(f64, bool)>().take(5)
/// .collect::<Vec<(f64, bool)>>());
/// ```
fn gen_iter<'a, T: Rand>(&'a mut self) -> Generator<'a, T, Self> where Self: Sized {
fn gen_iter<'a, T: Rand>(&'a mut self) -> Generator<'a, T, Self> {
Generator { rng: self, _marker: marker::PhantomData }
}

Expand Down Expand Up @@ -572,7 +572,7 @@ pub trait Rng: RngCore {
/// let m: f64 = rng.gen_range(-40.0f64, 1.3e5f64);
/// println!("{}", m);
/// ```
fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T {
assert!(low < high, "Rng::gen_range called with low >= high");
Range::new(low, high).ind_sample(self)
}
Expand All @@ -587,7 +587,7 @@ pub trait Rng: RngCore {
/// let mut rng = thread_rng();
/// println!("{}", rng.gen_weighted_bool(3));
/// ```
fn gen_weighted_bool(&mut self, n: u32) -> bool where Self: Sized {
fn gen_weighted_bool(&mut self, n: u32) -> bool {
n <= 1 || self.gen_range(0, n) == 0
}

Expand All @@ -601,7 +601,7 @@ pub trait Rng: RngCore {
/// let s: String = thread_rng().gen_ascii_chars().take(10).collect();
/// println!("{}", s);
/// ```
fn gen_ascii_chars<'a>(&'a mut self) -> AsciiGenerator<'a, Self> where Self: Sized {
fn gen_ascii_chars<'a>(&'a mut self) -> AsciiGenerator<'a, Self> {
AsciiGenerator { rng: self }
}

Expand All @@ -619,7 +619,7 @@ pub trait Rng: RngCore {
/// println!("{:?}", rng.choose(&choices));
/// assert_eq!(rng.choose(&choices[..0]), None);
/// ```
fn choose<'a, T>(&mut self, values: &'a [T]) -> Option<&'a T> where Self: Sized {
fn choose<'a, T>(&mut self, values: &'a [T]) -> Option<&'a T> {
if values.is_empty() {
None
} else {
Expand All @@ -630,7 +630,7 @@ pub trait Rng: RngCore {
/// Return a mutable pointer to a random element from `values`.
///
/// Return `None` if `values` is empty.
fn choose_mut<'a, T>(&mut self, values: &'a mut [T]) -> Option<&'a mut T> where Self: Sized {
fn choose_mut<'a, T>(&mut self, values: &'a mut [T]) -> Option<&'a mut T> {
if values.is_empty() {
None
} else {
Expand All @@ -656,7 +656,7 @@ pub trait Rng: RngCore {
/// rng.shuffle(&mut y);
/// println!("{:?}", y);
/// ```
fn shuffle<T>(&mut self, values: &mut [T]) where Self: Sized {
fn shuffle<T>(&mut self, values: &mut [T]) {
let mut i = values.len();
while i >= 2 {
// invariant: elements with index >= i have been locked in place.
Expand Down

0 comments on commit 0a7d935

Please sign in to comment.