Skip to content

Commit 03fc56c

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

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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)