|
18 | 18 | //! **`fn next_u32`:** |
19 | 19 | //! - `self.next_u64() as u32` |
20 | 20 | //! - `(self.next_u64() >> 32) as u32` |
21 | | -//! - <code>[next_u32_via_fill][](self)</code> |
| 21 | +//! - <code>[next_word_via_fill][](self)</code> |
22 | 22 | //! |
23 | 23 | //! **`fn next_u64`:** |
24 | 24 | //! - <code>[next_u64_via_u32][](self)</code> |
25 | | -//! - <code>[next_u64_via_fill][](self)</code> |
| 25 | +//! - <code>[next_word_via_fill][](self)</code> |
26 | 26 | //! |
27 | 27 | //! **`fn fill_bytes`:** |
28 | 28 | //! - <code>[fill_bytes_via_next_word][](self, dest)</code> |
@@ -98,18 +98,13 @@ pub(crate) fn fill_via_chunks<T: Word>(src: &[T], dest: &mut [u8]) -> (usize, us |
98 | 98 | (num_chunks, byte_len) |
99 | 99 | } |
100 | 100 |
|
101 | | -/// Implement `next_u32` via `fill_bytes`, little-endian order. |
102 | | -pub fn next_u32_via_fill<R: RngCore + ?Sized>(rng: &mut R) -> u32 { |
103 | | - let mut buf = [0; 4]; |
104 | | - rng.fill_bytes(&mut buf); |
105 | | - u32::from_le_bytes(buf) |
106 | | -} |
107 | | - |
108 | | -/// Implement `next_u64` via `fill_bytes`, little-endian order. |
109 | | -pub fn next_u64_via_fill<R: RngCore + ?Sized>(rng: &mut R) -> u64 { |
110 | | - let mut buf = [0; 8]; |
111 | | - rng.fill_bytes(&mut buf); |
112 | | - u64::from_le_bytes(buf) |
| 101 | +/// Yield a word using [`RngCore::fill_bytes`] |
| 102 | +/// |
| 103 | +/// This may be used to implement `next_u32` or `next_u64`. |
| 104 | +pub fn next_word_via_fill<W: Word, R: RngCore + ?Sized>(rng: &mut R) -> W { |
| 105 | + let mut buf: W::Bytes = Default::default(); |
| 106 | + rng.fill_bytes(buf.as_mut()); |
| 107 | + W::from_le_bytes(buf) |
113 | 108 | } |
114 | 109 |
|
115 | 110 | /// Fills `dst: &mut [u32]` from `src` |
|
0 commit comments