Skip to content

Commit

Permalink
Rng: remove Sized constraint
Browse files Browse the repository at this point in the history
Suggested in #287 and appears to work
  • Loading branch information
dhardy committed Mar 14, 2018
1 parent 31f2663 commit 253fa97
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,11 @@ pub trait Rand : Sized {
/// ```rust
/// use rand::Rng;
///
/// fn use_rng<R: Rng>(rng: &mut R) -> f32 {
/// fn use_rng<R: Rng + ?Sized>(rng: &mut R) -> f32 {
/// rng.gen()
/// }
/// ```
///
/// Since this trait exclusively uses generic methods, it is marked `Sized`.
/// Should it be necessary to support trait objects, use [`RngCore`].
/// Since `Rng` extends `RngCore` and every `RngCore` implements `Rng`, usage
/// of the two traits is somewhat interchangeable.
///
/// Iteration over an `Rng` can be achieved using `iter::repeat` as follows:
///
/// ```rust
Expand All @@ -373,7 +368,7 @@ pub trait Rand : Sized {
/// ```
///
/// [`RngCore`]: https://docs.rs/rand-core/0.1/rand-core/trait.RngCore.html
pub trait Rng: RngCore + Sized {
pub trait Rng: RngCore {
/// Fill `dest` entirely with random bytes (uniform value distribution),
/// where `dest` is any type supporting [`AsByteSliceMut`], namely slices
/// and arrays over primitive integer types (`i8`, `i16`, `u32`, etc.).
Expand All @@ -397,7 +392,7 @@ pub trait Rng: RngCore + Sized {
/// [`fill_bytes`]: https://docs.rs/rand-core/0.1/rand-core/trait.RngCore.html#method.fill_bytes
/// [`try_fill`]: trait.Rng.html#method.try_fill
/// [`AsByteSliceMut`]: trait.AsByteSliceMut.html
fn fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) where Self: Sized {
fn fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) {
self.fill_bytes(dest.as_byte_slice_mut());
dest.to_le();
}
Expand Down Expand Up @@ -433,7 +428,7 @@ pub trait Rng: RngCore + Sized {
/// [`try_fill_bytes`]: https://docs.rs/rand-core/0.1/rand-core/trait.RngCore.html#method.try_fill_bytes
/// [`fill`]: trait.Rng.html#method.fill
/// [`AsByteSliceMut`]: trait.AsByteSliceMut.html
fn try_fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) -> Result<(), Error> where Self: Sized {
fn try_fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) -> Result<(), Error> {
self.try_fill_bytes(dest.as_byte_slice_mut())?;
dest.to_le();
Ok(())
Expand All @@ -450,7 +445,7 @@ pub trait Rng: RngCore + Sized {
/// let mut rng = thread_rng();
/// let x: i32 = rng.sample(Range::new(10, 15));
/// ```
fn sample<T, D: Distribution<T>>(&mut self, distr: D) -> T where Self: Sized {
fn sample<T, D: Distribution<T>>(&mut self, distr: D) -> T {
distr.sample(self)
}

Expand Down

0 comments on commit 253fa97

Please sign in to comment.