Skip to content

Commit dd192ad

Browse files
committed
block: make doc example runnable
1 parent 2197f7b commit dd192ad

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/block.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
//!
66
//! # Example
77
//!
8-
//! ```no_run
8+
//! ```
99
//! use rand_core::{RngCore, SeedableRng};
1010
//! use rand_core::block::{Generator, BlockRng};
1111
//!
12-
//! struct MyRngCore;
12+
//! struct MyRngCore {
13+
//! // Generator state ...
14+
//! # state: [u32; 8],
15+
//! }
1316
//!
1417
//! impl Generator for MyRngCore {
15-
//! type Output = [u32; 16];
18+
//! type Output = [u32; 8];
1619
//!
1720
//! fn generate(&mut self, output: &mut Self::Output) {
18-
//! unimplemented!()
21+
//! // Write a new block to output...
22+
//! # *output = self.state;
1923
//! }
2024
//! }
2125
//!
@@ -27,7 +31,15 @@
2731
//! impl SeedableRng for MyRng {
2832
//! type Seed = [u8; 32];
2933
//! fn from_seed(seed: Self::Seed) -> Self {
30-
//! MyRng(BlockRng::new(MyRngCore))
34+
//! let core = MyRngCore {
35+
//! // ...
36+
//! # state: {
37+
//! # let mut buf = [0u32; 8];
38+
//! # rand_core::le::read_u32_into(&seed, &mut buf);
39+
//! # buf
40+
//! # }
41+
//! };
42+
//! MyRng(BlockRng::new(core))
3143
//! }
3244
//! }
3345
//!
@@ -50,6 +62,7 @@
5062
//!
5163
//! let mut rng = MyRng::seed_from_u64(0);
5264
//! println!("First value: {}", rng.next_u32());
65+
//! # assert_eq!(rng.next_u32(), 1171109249);
5366
//! ```
5467
//!
5568
//! # ReseedingRng

0 commit comments

Comments
 (0)