diff --git a/CHANGELOG.md b/CHANGELOG.md index 0780ced2..325ad7cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]. @@ -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 diff --git a/src/block.rs b/src/block.rs index c04abb61..db9a5ca4 100644 --- a/src/block.rs +++ b/src/block.rs @@ -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 @@ -124,6 +133,12 @@ impl fmt::Debug for BlockRng { } } +impl Drop for BlockRng { + fn drop(&mut self) { + self.core.drop(&mut self.results); + } +} + impl> BlockRng { /// Create a new `BlockRng` from an existing RNG implementing /// `Generator`. Results will be generated on first use.