Skip to content

Commit b714238

Browse files
committed
Add method fn Generator::drop
1 parent 5d19070 commit b714238

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Removed optional dependency `serde` ([#28])
1717
- Add `SeedableRng::fork` methods ([#17])
1818
- Rename trait `block::BlockRngCore` to `block::Generator` and associated type `Results` to `Output`; remove assoc. `type Item` and remove type bounds ([#26])
19+
- Add `fn drop` to trait `block::Generator` (#35)
20+
1921
### Other
2022
- Changed repository from [rust-random/rand] to [rust-random/core].
2123

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

3336
[rust-random/rand]: https://github.com/rust-random/rand
3437
[rust-random/core]: https://github.com/rust-random/core

src/block.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ pub trait Generator {
5959
///
6060
/// This must fill `output` with random data.
6161
fn generate(&mut self, output: &mut Self::Output);
62+
63+
/// Destruct the output buffer
64+
///
65+
/// This method is called on [`Drop`] of the [`Self::Output`] buffer.
66+
/// The default implementation does nothing.
67+
#[inline]
68+
fn drop(&mut self, output: &mut Self::Output) {
69+
let _ = output;
70+
}
6271
}
6372

6473
/// A cryptographically secure generator
@@ -124,6 +133,12 @@ impl<G: Generator + fmt::Debug> fmt::Debug for BlockRng<G> {
124133
}
125134
}
126135

136+
impl<G: Generator> Drop for BlockRng<G> {
137+
fn drop(&mut self) {
138+
self.core.drop(&mut self.results);
139+
}
140+
}
141+
127142
impl<const N: usize, G: Generator<Output = [u32; N]>> BlockRng<G> {
128143
/// Create a new `BlockRng` from an existing RNG implementing
129144
/// `Generator`. Results will be generated on first use.

0 commit comments

Comments
 (0)