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 Apr 29, 2018
1 parent d70d9db commit 3625bc1
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)
- Add `AsMut<[Self::Item]>` bound to `BlockRngCore::Results` (future-proofing). (#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 @@ -232,7 +232,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 @@ -435,7 +435,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 @@ -237,7 +237,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 3625bc1

Please sign in to comment.