Skip to content

Commit

Permalink
Require AsMut for BlockRngCore::Results
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed May 3, 2018
1 parent d8da965 commit 3a8ae17
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions rand_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rand_core/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<R: BlockRngCore> BlockRng<R> {
}

impl<R: BlockRngCore<Item=u32>> RngCore for BlockRng<R>
where <R as BlockRngCore>::Results: AsRef<[u32]>
where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
{
#[inline(always)]
fn next_u32(&mut self) -> u32 {
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<R: BlockRngCore> BlockRng64<R> {
}

impl<R: BlockRngCore<Item=u64>> RngCore for BlockRng64<R>
where <R as BlockRngCore>::Results: AsRef<[u64]>
where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
{
#[inline(always)]
fn next_u32(&mut self) -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/prng/isaac_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ impl<T> ::core::convert::AsRef<[T]> for IsaacArray<T> {
}
}

impl<T> ::core::convert::AsMut<[T]> for IsaacArray<T> {
#[inline(always)]
fn as_mut(&mut self) -> &mut [T] {
&mut self.inner[..]
}
}

impl<T> ::core::ops::Deref for IsaacArray<T> {
type Target = [T; RAND_SIZE];
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where R: BlockRngCore + SeedableRng,
// implements RngCore, but we can't specify that because ReseedingCore is private
impl<R, Rsdr: RngCore> RngCore for ReseedingRng<R, Rsdr>
where R: BlockRngCore<Item = u32> + SeedableRng,
<R as BlockRngCore>::Results: AsRef<[u32]>
<R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
{
#[inline(always)]
fn next_u32(&mut self) -> u32 {
Expand Down

0 comments on commit 3a8ae17

Please sign in to comment.