16
16
//! implementations only need to concern themselves with generation of the
17
17
//! block, not the various [`RngCore`] methods (especially [`fill_bytes`], where
18
18
//! the optimal implementations are not trivial), and this allows
19
- //! [`ReseedingRng`] perform periodic reseeding with very low overhead.
19
+ //! `ReseedingRng` (see [`rand`](https://docs.rs/rand) crate) perform periodic
20
+ //! reseeding with very low overhead.
20
21
//!
21
22
//! # Example
22
- //!
23
+ //!
23
24
//! ```norun
24
25
//! use rand_core::block::{BlockRngCore, BlockRng};
25
- //!
26
+ //!
26
27
//! struct MyRngCore;
27
- //!
28
+ //!
28
29
//! impl BlockRngCore for MyRngCore {
29
30
//! type Results = [u32; 16];
30
- //!
31
+ //!
31
32
//! fn generate(&mut self, results: &mut Self::Results) {
32
33
//! unimplemented!()
33
34
//! }
34
35
//! }
35
- //!
36
+ //!
36
37
//! impl SeedableRng for MyRngCore {
37
38
//! type Seed = unimplemented!();
38
39
//! fn from_seed(seed: Self::Seed) -> Self {
39
40
//! unimplemented!()
40
41
//! }
41
42
//! }
42
- //!
43
+ //!
43
44
//! // optionally, also implement CryptoRng for MyRngCore
44
- //!
45
+ //!
45
46
//! // Final RNG.
46
47
//! type MyRng = BlockRng<u32, MyRngCore>;
47
48
//! ```
48
- //!
49
- //! [`BlockRngCore`]: trait.BlockRngCore.html
50
- //! [`RngCore`]: ../trait.RngCore.html
51
- //! [`fill_bytes`]: ../trait.RngCore.html#tymethod.fill_bytes
52
- //! [`ReseedingRng`]: ../../rand/rngs/adapter/struct.ReseedingRng.html
49
+ //!
50
+ //! [`BlockRngCore`]: crate::block::BlockRngCore
51
+ //! [`fill_bytes`]: RngCore::fill_bytes
53
52
54
53
use core:: convert:: AsRef ;
55
54
use core:: fmt;
@@ -59,12 +58,12 @@ use impls::{fill_via_u32_chunks, fill_via_u64_chunks};
59
58
/// A trait for RNGs which do not generate random numbers individually, but in
60
59
/// blocks (typically `[u32; N]`). This technique is commonly used by
61
60
/// cryptographic RNGs to improve performance.
62
- ///
63
- /// See the [module documentation](index.html) for details.
61
+ ///
62
+ /// See the [module][crate::block] documentation for details.
64
63
pub trait BlockRngCore {
65
64
/// Results element type, e.g. `u32`.
66
65
type Item ;
67
-
66
+
68
67
/// Results type. This is the 'block' an RNG implementing `BlockRngCore`
69
68
/// generates, which will usually be an array like `[u32; 16]`.
70
69
type Results : AsRef < [ Self :: Item ] > + AsMut < [ Self :: Item ] > + Default ;
@@ -105,15 +104,10 @@ pub trait BlockRngCore {
105
104
///
106
105
/// For easy initialization `BlockRng` also implements [`SeedableRng`].
107
106
///
108
- /// [`BlockRngCore`]: BlockRngCore.t.html
109
- /// [`BlockRngCore::generate`]: trait.BlockRngCore.html#tymethod.generate
110
- /// [`BlockRng64`]: struct.BlockRng64.html
111
- /// [`RngCore`]: ../RngCore.t.html
112
- /// [`next_u32`]: ../trait.RngCore.html#tymethod.next_u32
113
- /// [`next_u64`]: ../trait.RngCore.html#tymethod.next_u64
114
- /// [`fill_bytes`]: ../trait.RngCore.html#tymethod.fill_bytes
115
- /// [`try_fill_bytes`]: ../trait.RngCore.html#tymethod.try_fill_bytes
116
- /// [`SeedableRng`]: ../SeedableRng.t.html
107
+ /// [`next_u32`]: RngCore::next_u32
108
+ /// [`next_u64`]: RngCore::next_u64
109
+ /// [`fill_bytes`]: RngCore::fill_bytes
110
+ /// [`try_fill_bytes`]: RngCore::try_fill_bytes
117
111
#[ derive( Clone ) ]
118
112
#[ cfg_attr( feature="serde1" , derive( Serialize , Deserialize ) ) ]
119
113
pub struct BlockRng < R : BlockRngCore + ?Sized > {
@@ -147,7 +141,7 @@ impl<R: BlockRngCore> BlockRng<R> {
147
141
}
148
142
149
143
/// Get the index into the result buffer.
150
- ///
144
+ ///
151
145
/// If this is equal to or larger than the size of the result buffer then
152
146
/// the buffer is "empty" and `generate()` must be called to produce new
153
147
/// results.
@@ -314,13 +308,10 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng<R> {
314
308
/// values. If the requested length is not a multiple of 8, some bytes will be
315
309
/// discarded.
316
310
///
317
- /// [`BlockRngCore`]: BlockRngCore.t.html
318
- /// [`RngCore`]: ../RngCore.t.html
319
- /// [`next_u32`]: ../trait.RngCore.html#tymethod.next_u32
320
- /// [`next_u64`]: ../trait.RngCore.html#tymethod.next_u64
321
- /// [`fill_bytes`]: ../trait.RngCore.html#tymethod.fill_bytes
322
- /// [`try_fill_bytes`]: ../trait.RngCore.html#tymethod.try_fill_bytes
323
- /// [`BlockRng`]: struct.BlockRng.html
311
+ /// [`next_u32`]: RngCore::next_u32
312
+ /// [`next_u64`]: RngCore::next_u64
313
+ /// [`fill_bytes`]: RngCore::fill_bytes
314
+ /// [`try_fill_bytes`]: RngCore::try_fill_bytes
324
315
#[ derive( Clone ) ]
325
316
#[ cfg_attr( feature="serde1" , derive( Serialize , Deserialize ) ) ]
326
317
pub struct BlockRng64 < R : BlockRngCore + ?Sized > {
0 commit comments