Require SeedableRng::Seed to impl Clone + AsRef (#1491)
This commit is contained in:
parent
9e030aa221
commit
71c53be9a9
@ -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)
|
||||
|
@ -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);
|
||||
@ -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
|
||||
@ -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.
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user