Skip to content

Commit fe12a45

Browse files
committed
Improve BlockRngCore doc
1 parent 34c5686 commit fe12a45

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

rand_core/src/block.rs

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,50 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! [`BlockRng`] trait and implementation helpers
11+
//! The `BlockRngCore` trait and implementation helpers
12+
//!
13+
//! The [`BlockRngCore`] trait exists to assist in the implementation of RNGs
14+
//! which generate a block of data in a cache instead of returning generated
15+
//! values directly.
16+
//!
17+
//! Usage of this trait is optional, but provides two advantages:
18+
//! implementations only need to concern themselves with generation of the
19+
//! block, not the various [`RngCore`] methods (especially [`fill_bytes`], where
20+
//! the optimal implementations are not trivial), and this allows
21+
//! [`ReseedingRng`] perform periodic reseeding with very low overhead.
22+
//!
23+
//! # Example
24+
//!
25+
//! ```norun
26+
//! use rand_core::block::{BlockRngCore, BlockRng};
27+
//!
28+
//! struct MyRngCore;
29+
//!
30+
//! impl BlockRngCore for MyRngCore {
31+
//! type Results = [u32; 16];
32+
//!
33+
//! fn generate(&mut self, results: &mut Self::Results) {
34+
//! unimplemented!()
35+
//! }
36+
//! }
37+
//!
38+
//! impl SeedableRng for MyRngCore {
39+
//! type Seed = unimplemented!();
40+
//! fn from_seed(seed: Self::Seed) -> Self {
41+
//! unimplemented!()
42+
//! }
43+
//! }
44+
//!
45+
//! // optionally, also implement CryptoRng for MyRngCore
46+
//!
47+
//! // Final RNG.
48+
//! type MyRng = BlockRng<u32, MyRngCore>;
49+
//! ```
50+
//!
51+
//! [`BlockRngCore`]: trait.BlockRngCore.html
52+
//! [`RngCore`]: ../trait.RngCore.html
53+
//! [`fill_bytes`]: ../trait.RngCore.html#tymethod.fill_bytes
54+
//! [`ReseedingRng`]: ../../rand/reseeding/struct.ReseedingRng.html
1255
1356
use core::convert::AsRef;
1457
use core::fmt;
@@ -19,42 +62,7 @@ use impls::{fill_via_u32_chunks, fill_via_u64_chunks};
1962
/// blocks (typically `[u32; N]`). This technique is commonly used by
2063
/// cryptographic RNGs to improve performance.
2164
///
22-
/// Usage of this trait is optional, but provides two advantages:
23-
/// implementations only need to concern themselves with generation of the
24-
/// block, not the various [`RngCore`] methods (especially [`fill_bytes`], where the
25-
/// optimal implementations are not trivial), and this allows `ReseedingRng` to
26-
/// perform periodic reseeding with very low overhead.
27-
///
28-
/// # Example
29-
///
30-
/// ```norun
31-
/// use rand_core::block::{BlockRngCore, BlockRng};
32-
///
33-
/// struct MyRngCore;
34-
///
35-
/// impl BlockRngCore for MyRngCore {
36-
/// type Results = [u32; 16];
37-
///
38-
/// fn generate(&mut self, results: &mut Self::Results) {
39-
/// unimplemented!()
40-
/// }
41-
/// }
42-
///
43-
/// impl SeedableRng for MyRngCore {
44-
/// type Seed = unimplemented!();
45-
/// fn from_seed(seed: Self::Seed) -> Self {
46-
/// unimplemented!()
47-
/// }
48-
/// }
49-
///
50-
/// // optionally, also implement CryptoRng for MyRngCore
51-
///
52-
/// // Final RNG.
53-
/// type MyRng = BlockRng<u32, MyRngCore>;
54-
/// ```
55-
///
56-
/// [`RngCore`]: ../trait.RngCore.html
57-
/// [`fill_bytes`]: ../trait.RngCore.html#tymethod.fill_bytes
65+
/// See the [module documentation](index.html) for details.
5866
pub trait BlockRngCore {
5967
/// Results element type, e.g. `u32`.
6068
type Item;

0 commit comments

Comments
 (0)