Skip to content

Commit b2fd82d

Browse files
committed
Rng: remove Sized constraint
Suggested in #287 and appears to work
1 parent 336d224 commit b2fd82d

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,11 @@ pub trait Rand : Sized {
337337
/// ```rust
338338
/// use rand::Rng;
339339
///
340-
/// fn use_rng<R: Rng>(rng: &mut R) -> f32 {
340+
/// fn use_rng<R: Rng + ?Sized>(rng: &mut R) -> f32 {
341341
/// rng.gen()
342342
/// }
343343
/// ```
344344
///
345-
/// Since this trait exclusively uses generic methods, it is marked `Sized`.
346-
/// Should it be necessary to support trait objects, use [`RngCore`].
347-
/// Since `Rng` extends `RngCore` and every `RngCore` implements `Rng`, usage
348-
/// of the two traits is somewhat interchangeable.
349-
///
350345
/// Iteration over an `Rng` can be achieved using `iter::repeat` as follows:
351346
///
352347
/// ```rust
@@ -373,7 +368,7 @@ pub trait Rand : Sized {
373368
/// ```
374369
///
375370
/// [`RngCore`]: https://docs.rs/rand-core/0.1/rand-core/trait.RngCore.html
376-
pub trait Rng: RngCore + Sized {
371+
pub trait Rng: RngCore {
377372
/// Fill `dest` entirely with random bytes (uniform value distribution),
378373
/// where `dest` is any type supporting [`AsByteSliceMut`], namely slices
379374
/// and arrays over primitive integer types (`i8`, `i16`, `u32`, etc.).
@@ -397,7 +392,7 @@ pub trait Rng: RngCore + Sized {
397392
/// [`fill_bytes`]: https://docs.rs/rand-core/0.1/rand-core/trait.RngCore.html#method.fill_bytes
398393
/// [`try_fill`]: trait.Rng.html#method.try_fill
399394
/// [`AsByteSliceMut`]: trait.AsByteSliceMut.html
400-
fn fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) where Self: Sized {
395+
fn fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) {
401396
self.fill_bytes(dest.as_byte_slice_mut());
402397
dest.to_le();
403398
}
@@ -433,7 +428,7 @@ pub trait Rng: RngCore + Sized {
433428
/// [`try_fill_bytes`]: https://docs.rs/rand-core/0.1/rand-core/trait.RngCore.html#method.try_fill_bytes
434429
/// [`fill`]: trait.Rng.html#method.fill
435430
/// [`AsByteSliceMut`]: trait.AsByteSliceMut.html
436-
fn try_fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) -> Result<(), Error> where Self: Sized {
431+
fn try_fill<T: AsByteSliceMut + ?Sized>(&mut self, dest: &mut T) -> Result<(), Error> {
437432
self.try_fill_bytes(dest.as_byte_slice_mut())?;
438433
dest.to_le();
439434
Ok(())
@@ -450,7 +445,7 @@ pub trait Rng: RngCore + Sized {
450445
/// let mut rng = thread_rng();
451446
/// let x: i32 = rng.sample(Range::new(10, 15));
452447
/// ```
453-
fn sample<T, D: Distribution<T>>(&mut self, distr: D) -> T where Self: Sized {
448+
fn sample<T, D: Distribution<T>>(&mut self, distr: D) -> T {
454449
distr.sample(self)
455450
}
456451

0 commit comments

Comments
 (0)