From 3a8ae170c678caf9d6ebacc04256c1e90631e50d Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sun, 29 Apr 2018 16:10:59 +0200 Subject: [PATCH] Require AsMut for BlockRngCore::Results --- rand_core/CHANGELOG.md | 1 + rand_core/src/impls.rs | 4 ++-- rand_core/src/lib.rs | 2 +- src/prng/isaac_array.rs | 7 +++++++ src/reseeding.rs | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rand_core/CHANGELOG.md b/rand_core/CHANGELOG.md index ebde39eca60..79603a4f438 100644 --- a/rand_core/CHANGELOG.md +++ b/rand_core/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Enable the `std` feature by default. (#409) - Change `BlockRng64::inner` and add `BlockRng64::inner_mut` to mirror `BlockRng`. (#419) - Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419) +- Change `BlockRngCore::Results` bound to also require `AsMut<[Self::Item]>`. (#419) ## [0.1.0] - 2018-04-17 (Split out of the Rand crate, changes here are relative to rand 0.4.2) diff --git a/rand_core/src/impls.rs b/rand_core/src/impls.rs index 46166de5b97..54b122e07b9 100644 --- a/rand_core/src/impls.rs +++ b/rand_core/src/impls.rs @@ -249,7 +249,7 @@ impl BlockRng { } impl> RngCore for BlockRng -where ::Results: AsRef<[u32]> +where ::Results: AsRef<[u32]> + AsMut<[u32]> { #[inline(always)] fn next_u32(&mut self) -> u32 { @@ -448,7 +448,7 @@ impl BlockRng64 { } impl> RngCore for BlockRng64 -where ::Results: AsRef<[u64]> +where ::Results: AsRef<[u64]> + AsMut<[u64]> { #[inline(always)] fn next_u32(&mut self) -> u32 { diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index 4d2f997967b..fc8c419eeb3 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -238,7 +238,7 @@ pub trait BlockRngCore { /// Results type. This is the 'block' an RNG implementing `BlockRngCore` /// generates, which will usually be an array like `[u32; 16]`. - type Results: AsRef<[Self::Item]> + Default; + type Results: AsRef<[Self::Item]> + AsMut<[Self::Item]> + Default; /// Generate a new block of results. fn generate(&mut self, results: &mut Self::Results); diff --git a/src/prng/isaac_array.rs b/src/prng/isaac_array.rs index 327cfbf5bcf..3ebf828c684 100644 --- a/src/prng/isaac_array.rs +++ b/src/prng/isaac_array.rs @@ -38,6 +38,13 @@ impl ::core::convert::AsRef<[T]> for IsaacArray { } } +impl ::core::convert::AsMut<[T]> for IsaacArray { + #[inline(always)] + fn as_mut(&mut self) -> &mut [T] { + &mut self.inner[..] + } +} + impl ::core::ops::Deref for IsaacArray { type Target = [T; RAND_SIZE]; #[inline(always)] diff --git a/src/reseeding.rs b/src/reseeding.rs index 0f7f049429a..c74862cbdde 100644 --- a/src/reseeding.rs +++ b/src/reseeding.rs @@ -84,7 +84,7 @@ where R: BlockRngCore + SeedableRng, // implements RngCore, but we can't specify that because ReseedingCore is private impl RngCore for ReseedingRng where R: BlockRngCore + SeedableRng, - ::Results: AsRef<[u32]> + ::Results: AsRef<[u32]> + AsMut<[u32]> { #[inline(always)] fn next_u32(&mut self) -> u32 {