Struct BlockRng
pub struct BlockRng<G: Generator> { pub core: G, /* private fields */ }
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
generatefunction.
Implementations
impl<W: Word + Default, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G>
fn new(core: G) -> BlockRng<G>Create a new
BlockRngfrom an existing RNG implementingGenerator. Results will be generated on first use.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
coreand the output ofSelf::remaining_results.Returns
Noneifremaining_resultsis too long.
impl<W: Word, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G>
fn fill_bytes(&mut self, dest: &mut [u8])Fill
dest
impl<W: Word, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G>
fn reset_and_skip(&mut self, n: usize)Re-generate buffer contents, skipping the first
nwordsExisting buffer contents are discarded. A new set of results is generated (either immediately or when next required). The first
nwords are skipped (this may be used to set a specific word position).Panics
This method will panic if
n >= NwhereNis the buffer size (in words).fn word_offset(&self) -> usizeGet the number of words consumed since the start of the block
The result is in the range
0..NwhereNis the buffer size (in words).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 thanNwhereOutput = [W; N]).This is a low-level interface intended for serialization. Results are not marked as consumed.
fn next_word(&mut self) -> WGenerate the next word (e.g.
u32)
impl<const N: usize, G: Generator<Output = [u32; N]>> BlockRng<G>
fn next_u64_from_u32(&mut self) -> u64Generate a
u64from twou32words
Trait Implementations
impl<G> Debug for BlockRng<G>
where
G: Generator + Debug,
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl<G: Clone + Generator> Clone for BlockRng<G>
where
G::Output: Clone,
fn clone(&self) -> BlockRng<G>
impl<G: Generator> Drop for BlockRng<G>
fn drop(&mut self)
Auto Trait Implementations
impl<G> Freeze for BlockRng<G>
where
<G as Generator>::Output: Freeze,
G: Freeze,
impl<G> RefUnwindSafe for BlockRng<G>
where
<G as Generator>::Output: RefUnwindSafe,
G: RefUnwindSafe,
impl<G> Send for BlockRng<G>
where
<G as Generator>::Output: Send,
G: Send,
impl<G> Sync for BlockRng<G>
where
<G as Generator>::Output: Sync,
G: Sync,
impl<G> Unpin for BlockRng<G>
where
<G as Generator>::Output: Unpin,
G: Unpin,
impl<G> UnsafeUnpin for BlockRng<G>
where
<G as Generator>::Output: UnsafeUnpin,
G: UnsafeUnpin,
impl<G> UnwindSafe for BlockRng<G>
where
<G as Generator>::Output: UnwindSafe,
G: UnwindSafe,
Blanket Implementations
impl<T> Any for BlockRng<G>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for BlockRng<G>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for BlockRng<G>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for BlockRng<G>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for BlockRng<G>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for BlockRng<G>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for BlockRng<G>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for BlockRng<G>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>