pub trait NonceRng {
    // Required method
    fn fill_bytes(&self, bytes: &mut [u8]);
}
Expand description

A helper trait over RNGs that handle internal mutablility.

Used by the Synthetic nonce generator.

RngCore requires self to be mutable which is annoying in our context. This trait requires the rng be able to create randomness without being mutable. The most strightforward way of doing this is to use rngs instances like ThreadRng that have a Default implementation are and seeded from the system. See GlobalRng.

If you want to BYO rng you have to either implement this trait or wrap the RngCore in a RefCell or Mutex.

Required Methods§

source

fn fill_bytes(&self, bytes: &mut [u8])

Fill bytes with random data.

Implementations on Foreign Types§

source§

impl<R: RngCore> NonceRng for RefCell<R>

source§

fn fill_bytes(&self, bytes: &mut [u8])

source§

impl<R: RngCore> NonceRng for Mutex<R>

Available on crate feature std only.
source§

fn fill_bytes(&self, bytes: &mut [u8])

Implementors§

source§

impl<R: RngCore + Default> NonceRng for GlobalRng<R>

We implement NonceRng only for rngs we can conjure out of thin air with Default.