pub struct BlockRng<G: Generator> {
pub core: G,
/* private fields */
}Expand description
RNG functionality for a block Generator
This type encompasses a Generator core and a buffer.
It provides optimized implementations of methods required by an Rng.
All values are consumed in-order of generation. No whole words (e.g. u32
or u64) are discarded, though where a word is partially used (e.g. for a
byte-fill whose length is not a multiple of the word size) the rest of the
word is discarded.
Fields§
§core: GThe core part of the RNG, implementing the generate function.
Implementations§
Source§impl<W: Word + Default, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G>
impl<W: Word + Default, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G>
Sourcepub fn new(core: G) -> BlockRng<G>
pub fn new(core: G) -> BlockRng<G>
Create a new BlockRng from an existing RNG implementing
Generator. Results will be generated on first use.
Sourcepub fn reconstruct(core: G, remaining_results: &[W]) -> Option<Self>
pub fn reconstruct(core: G, remaining_results: &[W]) -> Option<Self>
Reconstruct from a core and a remaining-results buffer.
This may be used to deserialize using a core and the output of
Self::remaining_results.
Returns None if remaining_results is too long.
Source§impl<W: Word, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G>
impl<W: Word, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G>
Sourcepub fn reset_and_skip(&mut self, n: usize)
pub fn reset_and_skip(&mut self, n: usize)
Re-generate buffer contents, skipping the first n words
Existing buffer contents are discarded. A new set of results is
generated (either immediately or when next required). The first n
words are skipped (this may be used to set a specific word position).
§Panics
This method will panic if n >= N where N is the buffer size (in
words).
Sourcepub fn word_offset(&self) -> usize
pub fn word_offset(&self) -> usize
Get the number of words consumed since the start of the block
The result is in the range 0..N where N is the buffer size (in
words).
Sourcepub fn remaining_results(&self) -> &[W]
pub fn remaining_results(&self) -> &[W]
Access the unused part of the results buffer
The length of the returned slice is guaranteed to be less than the
length of <Self as Generator>::Output (i.e. less than N where
Output = [W; N]).
This is a low-level interface intended for serialization. Results are not marked as consumed.