pub struct BlockRng<G>where
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, const N: usize, G> BlockRng<G>
impl<W, const N: usize, G> 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<BlockRng<G>>
pub fn reconstruct(core: G, remaining_results: &[W]) -> Option<BlockRng<G>>
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, const N: usize, G> BlockRng<G>
impl<W, const N: usize, G> 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.
Trait Implementations§
Auto Trait Implementations§
impl<G> Freeze for BlockRng<G>
impl<G> RefUnwindSafe for BlockRng<G>
impl<G> Send for BlockRng<G>
impl<G> Sync for BlockRng<G>
impl<G> Unpin for BlockRng<G>
impl<G> UnsafeUnpin for BlockRng<G>
impl<G> UnwindSafe for BlockRng<G>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more