pub struct EntropyPool { /* private fields */ }Expand description
A pre-warmed pool of EntropySnapshot values for low-latency draws.
The pool spawns a background thread that continuously generates snapshots
via entropy::gather() and refills the pool whenever it falls below a
watermark (50% of capacity). Draws are nearly instant (mutex lock + pop).
If the pool is temporarily exhausted, draw() falls back to a synchronous
entropy::gather() call so correctness is never compromised.
Implementations§
Source§impl EntropyPool
impl EntropyPool
Sourcepub fn new(capacity: usize) -> Result<Self>
pub fn new(capacity: usize) -> Result<Self>
Create a new pool that holds up to capacity pre-generated snapshots.
Blocks until at least 8 snapshots (or capacity, whichever is smaller)
are ready. The background refill thread starts immediately.
§Panics
If capacity is 0.
Sourcepub fn draw(&self) -> Result<EntropySnapshot>
pub fn draw(&self) -> Result<EntropySnapshot>
Draw a single EntropySnapshot from the pool.
If the pool has snapshots ready, this is a fast mutex-pop (~ns).
If the pool is exhausted, falls back to synchronous entropy::gather().
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EntropyPool
impl RefUnwindSafe for EntropyPool
impl Send for EntropyPool
impl Sync for EntropyPool
impl Unpin for EntropyPool
impl UnsafeUnpin for EntropyPool
impl UnwindSafe for EntropyPool
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> 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