Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed optional dependency `serde` ([#28])
- Add `SeedableRng::fork` methods ([#17])
- Rename trait `block::BlockRngCore` to `block::Generator` and associated type `Results` to `Output`; remove assoc. `type Item` and remove type bounds ([#26])
- Add `fn drop` to trait `block::Generator` (#35)

### Other
- Changed repository from [rust-random/rand] to [rust-random/core].

Expand All @@ -29,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#17]: https://github.com/rust-random/rand-core/pull/17
[#26]: https://github.com/rust-random/rand-core/pull/28
[#28]: https://github.com/rust-random/rand-core/pull/28
[#35]: https://github.com/rust-random/rand-core/pull/35

[rust-random/rand]: https://github.com/rust-random/rand
[rust-random/core]: https://github.com/rust-random/core
Expand Down
15 changes: 15 additions & 0 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ pub trait Generator {
///
/// This must fill `output` with random data.
fn generate(&mut self, output: &mut Self::Output);

/// Destruct the output buffer
///
/// This method is called on [`Drop`] of the [`Self::Output`] buffer.
/// The default implementation does nothing.
#[inline]
fn drop(&mut self, output: &mut Self::Output) {
let _ = output;
}
}

/// A cryptographically secure generator
Expand Down Expand Up @@ -124,6 +133,12 @@ impl<G: Generator + fmt::Debug> fmt::Debug for BlockRng<G> {
}
}

impl<G: Generator> Drop for BlockRng<G> {
fn drop(&mut self) {
self.core.drop(&mut self.results);
}
}

impl<const N: usize, G: Generator<Output = [u32; N]>> BlockRng<G> {
/// Create a new `BlockRng` from an existing RNG implementing
/// `Generator`. Results will be generated on first use.
Expand Down