pub(crate) struct RngBuffer<'a, T: RngCore> {
inner: &'a mut T,
u8_vec: ArrayVec<u8, 7>,
u32_opt: Option<u32>,
}
Expand description
Wrap a RngCore
implementation for fast u8
and u32
output.
This maintains small queues for each data type: up to one u32
and up to
7 bytes. The queueing behavior matches convenions required by HashX:
The underlying u64
values are always generated lazily, and component
values are extracted in big endian order.
Fields§
§inner: &'a mut T
Inner RngCore
implementation
u8_vec: ArrayVec<u8, 7>
Buffer of remaining u8 values from breaking up a u64
u32_opt: Option<u32>
Up to one buffered u32 value
Implementations§
Source§impl<'a, T: RngCore> RngBuffer<'a, T>
impl<'a, T: RngCore> RngBuffer<'a, T>
Sourcepub(crate) fn new(rng: &'a mut T) -> Self
pub(crate) fn new(rng: &'a mut T) -> Self
Construct a new empty buffer around a RngCore
implementation.
No actual random numbers will be generated until the first call to
Self::next_u8
or Self::next_u32
.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for RngBuffer<'a, T>
impl<'a, T> RefUnwindSafe for RngBuffer<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for RngBuffer<'a, T>where
T: Send,
impl<'a, T> Sync for RngBuffer<'a, T>where
T: Sync,
impl<'a, T> Unpin for RngBuffer<'a, T>
impl<'a, T> !UnwindSafe for RngBuffer<'a, T>
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
Mutably borrows from an owned value. Read more