pub struct DevRng(/* private fields */);Expand description
Reproducible random generator for tests
Implementations§
Source§impl DevRng
impl DevRng
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs randomness generator
Reads a seed from env variable RUST_TESTS_SEED or generates a random seed if env variable is not set.
Prints seed to stderr.
Panics if RUST_TESTS_SEED contains invalid value.
Sourcepub fn fork(&mut self) -> Self
pub fn fork(&mut self) -> Self
Derives another randomness generator from this instance
Uses self to generate a seed and constructs a new instance of DevRng from the seed.
May be useful when you have several threads/futures/places where you need access the randomness generation, but you don’t want to mess with ownership system.
Trait Implementations§
Source§impl SeedableRng for DevRng
impl SeedableRng for DevRng
Source§type Seed = <ChaCha8Rng as SeedableRng>::Seed
type Seed = <ChaCha8Rng as SeedableRng>::Seed
Seed type, which is restricted to types mutably-dereferenceable as
u8
arrays (we recommend [u8; N] for some N). Read moreSource§fn seed_from_u64(state: u64) -> Self
fn seed_from_u64(state: u64) -> Self
Create a new PRNG using a
u64 seed. Read moreSource§fn from_rng(rng: &mut impl RngCore) -> Self
fn from_rng(rng: &mut impl RngCore) -> Self
Create a new PRNG seeded from an infallible
Rng. Read moreSource§fn try_from_rng<R: TryRngCore>(rng: &mut R) -> Result<Self, R::Error>
fn try_from_rng<R: TryRngCore>(rng: &mut R) -> Result<Self, R::Error>
Create a new PRNG seeded from a potentially fallible
Rng. Read moreSource§fn from_os_rng() -> Self
fn from_os_rng() -> Self
impl CryptoRng for DevRng
Auto Trait Implementations§
impl Freeze for DevRng
impl RefUnwindSafe for DevRng
impl Send for DevRng
impl Sync for DevRng
impl Unpin for DevRng
impl UnwindSafe for DevRng
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a RNG error.
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
Return the next random
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
Return the next random
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
Fill
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
Wrap RNG with the
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
Convert an
RngCore to a RngReadAdapter.