8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
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
12
55
13
56
use core:: convert:: AsRef ;
14
57
use core:: fmt;
@@ -19,42 +62,7 @@ use impls::{fill_via_u32_chunks, fill_via_u64_chunks};
19
62
/// blocks (typically `[u32; N]`). This technique is commonly used by
20
63
/// cryptographic RNGs to improve performance.
21
64
///
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.
58
66
pub trait BlockRngCore {
59
67
/// Results element type, e.g. `u32`.
60
68
type Item ;
0 commit comments