Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
- Rename `rand::distributions` to `rand::distr` (#1470)
- The `serde1` feature has been renamed `serde` (#1477)
- Mark `WeightError`, `PoissonError`, `BinomialError` as `#[non_exhaustive]` (#1480).
- Require `Clone` and `AsRef` bound for `SeedableRng::Seed`. (#1491)

## [0.9.0-alpha.1] - 2024-03-18
- Add the `Slice::num_choices` method to the Slice distribution (#1402)
Expand Down
17 changes: 11 additions & 6 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,15 @@ pub trait SeedableRng: Sized {
///
/// # Implementing `SeedableRng` for RNGs with large seeds
///
/// Note that the required traits `core::default::Default` and
/// `core::convert::AsMut<u8>` are not implemented for large arrays
/// `[u8; N]` with `N` > 32. To be able to implement the traits required by
/// `SeedableRng` for RNGs with such large seeds, the newtype pattern can be
/// used:
/// Note that [`Default`] is not implemented for large arrays `[u8; N]` with
/// `N` > 32. To be able to implement the traits required by `SeedableRng`
/// for RNGs with such large seeds, the newtype pattern can be used:
///
/// ```
/// use rand_core::SeedableRng;
///
/// const N: usize = 64;
/// #[derive(Clone)]
/// pub struct MyRngSeed(pub [u8; N]);
/// # #[allow(dead_code)]
/// pub struct MyRng(MyRngSeed);
Expand All @@ -299,6 +298,12 @@ pub trait SeedableRng: Sized {
/// }
/// }
///
/// impl AsRef<[u8]> for MyRngSeed {
/// fn as_ref(&self) -> &[u8] {
/// &self.0
/// }
/// }
///
/// impl AsMut<[u8]> for MyRngSeed {
/// fn as_mut(&mut self) -> &mut [u8] {
/// &mut self.0
Expand All @@ -313,7 +318,7 @@ pub trait SeedableRng: Sized {
/// }
/// }
/// ```
type Seed: Sized + Default + AsMut<[u8]>;
type Seed: Clone + Default + AsRef<[u8]> + AsMut<[u8]>;

/// Create a new PRNG using the given seed.
///
Expand Down