Skip to content

Commit d81834e

Browse files
committed
block: make doc example runnable
1 parent b2e86c8 commit d81834e

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
@@ -13,17 +13,21 @@
1313
//!
1414
//! # Example
1515
//!
16-
//! ```no_run
16+
//! ```
1717
//! use rand_core::{RngCore, SeedableRng};
1818
//! use rand_core::block::{Generator, BlockRng};
1919
//!
20-
//! struct MyRngCore;
20+
//! struct MyRngCore {
21+
//! // Generator state ...
22+
//! # state: [u32; 8],
23+
//! }
2124
//!
2225
//! impl Generator for MyRngCore {
23-
//! type Output = [u32; 16];
26+
//! type Output = [u32; 8];
2427
//!
2528
//! fn generate(&mut self, output: &mut Self::Output) {
26-
//! unimplemented!()
29+
//! // Write a new block to output...
30+
//! # *output = self.state;
2731
//! }
2832
//! }
2933
//!
@@ -33,7 +37,15 @@
3337
//! impl SeedableRng for MyRng {
3438
//! type Seed = [u8; 32];
3539
//! fn from_seed(seed: Self::Seed) -> Self {
36-
//! MyRng(BlockRng::new(MyRngCore))
40+
//! let core = MyRngCore {
41+
//! // ...
42+
//! # state: {
43+
//! # let mut buf = [0u32; 8];
44+
//! # rand_core::le::read_u32_into(&seed, &mut buf);
45+
//! # buf
46+
//! # }
47+
//! };
48+
//! MyRng(BlockRng::new(core))
3749
//! }
3850
//! }
3951
//!
@@ -58,6 +70,7 @@
5870
//!
5971
//! let mut rng = MyRng::seed_from_u64(0);
6072
//! println!("First value: {}", rng.next_u32());
73+
//! # assert_eq!(rng.next_u32(), 1171109249);
6174
//! ```
6275
//!
6376
//! # ReseedingRng

0 commit comments

Comments
 (0)