Skip to content

Commit 3393187

Browse files
committed
Fix block RNG example
1 parent e9d28d3 commit 3393187

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/block.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,37 @@
2727
//! }
2828
//! }
2929
//!
30-
//! impl SeedableRng for MyRngCore {
30+
//! // optionally, also implement CryptoGenerator and SeedableRng for MyRngCore
31+
//!
32+
//! // Final RNG.
33+
//! struct MyRng(BlockRng<MyRngCore>);
34+
//!
35+
//! impl SeedableRng for MyRng {
3136
//! type Seed = [u8; 32];
3237
//! fn from_seed(seed: Self::Seed) -> Self {
33-
//! unimplemented!()
38+
//! MyRng(BlockRng::new(MyRngCore))
3439
//! }
3540
//! }
3641
//!
37-
//! // optionally, also implement CryptoGenerator for MyRngCore
42+
//! impl RngCore for MyRng {
43+
//! #[inline]
44+
//! fn next_u32(&mut self) -> u32 {
45+
//! self.0.next_word()
46+
//! }
3847
//!
39-
//! // Final RNG.
40-
//! let mut rng = BlockRng::new(MyRngCore::seed_from_u64(0));
41-
//! println!("First value: {}", rng.next_word());
48+
//! #[inline]
49+
//! fn next_u64(&mut self) -> u64 {
50+
//! self.0.next_u64_from_u32()
51+
//! }
52+
//!
53+
//! #[inline]
54+
//! fn fill_bytes(&mut self, bytes: &mut [u8]) {
55+
//! self.0.fill_bytes(bytes)
56+
//! }
57+
//! }
58+
//!
59+
//! let mut rng = MyRng::seed_from_u64(0);
60+
//! println!("First value: {}", rng.next_u32());
4261
//! ```
4362
//!
4463
//! [`Generator`]: crate::block::Generator

0 commit comments

Comments
 (0)