Skip to content

Commit f6d2e96

Browse files
committed
Address feedback
- Use `Rng` bounds in `slice.rs` - Fixup documentation in `rng.rs` - Bump `rand` and `rand_pcg` versions
1 parent 70dca8d commit f6d2e96

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand"
3-
version = "0.10.0-rc.7"
3+
version = "0.10.0-rc.8"
44
authors = ["The Rand Project Developers", "The Rust Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"

rand_pcg/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_pcg"
3-
version = "0.10.0-rc.6"
3+
version = "0.10.0-rc.7"
44
authors = ["The Rand Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"

src/distr/slice.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
use core::num::NonZeroUsize;
1212

13+
use crate::Rng;
1314
use crate::distr::Distribution;
1415
use crate::distr::uniform::{UniformSampler, UniformUsize};
1516
#[cfg(feature = "alloc")]
@@ -83,7 +84,7 @@ impl<'a, T> Choose<'a, T> {
8384
}
8485

8586
impl<'a, T> Distribution<&'a T> for Choose<'a, T> {
86-
fn sample<R: crate::RngExt + ?Sized>(&self, rng: &mut R) -> &'a T {
87+
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> &'a T {
8788
let idx = self.range.sample(rng);
8889

8990
debug_assert!(
@@ -120,12 +121,7 @@ impl std::error::Error for Empty {}
120121

121122
#[cfg(feature = "alloc")]
122123
impl super::SampleString for Choose<'_, char> {
123-
fn append_string<R: crate::RngExt + ?Sized>(
124-
&self,
125-
rng: &mut R,
126-
string: &mut String,
127-
len: usize,
128-
) {
124+
fn append_string<R: Rng + ?Sized>(&self, rng: &mut R, string: &mut String, len: usize) {
129125
// Get the max char length to minimize extra space.
130126
// Limit this check to avoid searching for long slice.
131127
let max_char_len = if self.slice.len() < 200 {

src/rng.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ use rand_core::Rng;
2121
/// (Number) Generators. This trait, `Rng`, provides a user-level interface on
2222
/// RNGs. It is implemented automatically for any `R: Rng`.
2323
///
24-
/// This trait must usually be brought into scope via `use rand::Rng;` or
24+
/// This trait must usually be brought into scope via `use rand::RngExt;` or
2525
/// `use rand::prelude::*;`.
2626
///
2727
/// # Generic usage
2828
///
2929
/// The basic pattern is `fn foo<R: Rng + ?Sized>(rng: &mut R)`. Some
3030
/// things are worth noting here:
3131
///
32-
/// - Since `Rng: Rng` and every `Rng` implements `Rng`, it makes no
33-
/// difference whether we use `R: Rng` or `R: Rng`.
34-
/// - The `+ ?Sized` un-bounding allows functions to be called directly on
35-
/// type-erased references; i.e. `foo(r)` where `r: &mut dyn Rng`. Without
36-
/// this it would be necessary to write `foo(&mut r)`.
32+
/// - Since `RngExt: Rng` and every `RngExt` implements `Rng`, it makes no
33+
/// difference whether we use `R: Rng` or `R: RngExt` for `R: Sized`.
34+
/// - Only `Rng` is dyn safe, supporting `&mut dyn Rng` and `R: Rng + ?Sized`.
3735
///
3836
/// An alternative pattern is possible: `fn foo<R: Rng>(rng: R)`. This has some
3937
/// trade-offs. It allows the argument to be consumed directly without a `&mut`

0 commit comments

Comments
 (0)