Skip to content

Commit ecf5bcb

Browse files
committed
Require AsMut for BlockRngCore::Results
1 parent 837ca42 commit ecf5bcb

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

rand_core/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Enable the `std` feature by default. (#409)
1010
- Change `BlockRng64::inner` and add `BlockRng64::inner_mut` to mirror `BlockRng`. (#419)
1111
- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419)
12+
- Change `BlockRngCore::Results` bound to also require `AsMut<[Self::Item]>`. (#419)
1213

1314
## [0.1.0] - 2018-04-17
1415
(Split out of the Rand crate, changes here are relative to rand 0.4.2)

rand_core/src/impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<R: BlockRngCore> BlockRng<R> {
249249
}
250250

251251
impl<R: BlockRngCore<Item=u32>> RngCore for BlockRng<R>
252-
where <R as BlockRngCore>::Results: AsRef<[u32]>
252+
where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
253253
{
254254
#[inline(always)]
255255
fn next_u32(&mut self) -> u32 {
@@ -448,7 +448,7 @@ impl<R: BlockRngCore> BlockRng64<R> {
448448
}
449449

450450
impl<R: BlockRngCore<Item=u64>> RngCore for BlockRng64<R>
451-
where <R as BlockRngCore>::Results: AsRef<[u64]>
451+
where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
452452
{
453453
#[inline(always)]
454454
fn next_u32(&mut self) -> u32 {

rand_core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub trait BlockRngCore {
237237

238238
/// Results type. This is the 'block' an RNG implementing `BlockRngCore`
239239
/// generates, which will usually be an array like `[u32; 16]`.
240-
type Results: AsRef<[Self::Item]> + Default;
240+
type Results: AsRef<[Self::Item]> + AsMut<[Self::Item]> + Default;
241241

242242
/// Generate a new block of results.
243243
fn generate(&mut self, results: &mut Self::Results);

src/prng/isaac_array.rs

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ impl<T> ::core::convert::AsRef<[T]> for IsaacArray<T> {
3838
}
3939
}
4040

41+
impl<T> ::core::convert::AsMut<[T]> for IsaacArray<T> {
42+
#[inline(always)]
43+
fn as_mut(&mut self) -> &mut [T] {
44+
&mut self.inner[..]
45+
}
46+
}
47+
4148
impl<T> ::core::ops::Deref for IsaacArray<T> {
4249
type Target = [T; RAND_SIZE];
4350
#[inline(always)]

src/reseeding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ where R: BlockRngCore + SeedableRng,
8484
// implements RngCore, but we can't specify that because ReseedingCore is private
8585
impl<R, Rsdr: RngCore> RngCore for ReseedingRng<R, Rsdr>
8686
where R: BlockRngCore<Item = u32> + SeedableRng,
87-
<R as BlockRngCore>::Results: AsRef<[u32]>
87+
<R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
8888
{
8989
#[inline(always)]
9090
fn next_u32(&mut self) -> u32 {

0 commit comments

Comments
 (0)