pub struct MockRng<I>(pub I);
Expand description
Random number generator mock.
Produces randomness directly from the given iterator and panics when it runs out of items.
Tuple Fields
0: I
Implementations
sourceimpl<'a> MockRng<Copied<Iter<'a, u64>>>
impl<'a> MockRng<Copied<Iter<'a, u64>>>
sourcepub fn slice(slice: &'a [u64]) -> Random<Self>ⓘNotable traits for Random<R>impl<R: Rng> Read for Random<R>
pub fn slice(slice: &'a [u64]) -> Random<Self>ⓘNotable traits for Random<R>impl<R: Rng> Read for Random<R>
Produces the values from the input slice as the underlying random number generator.
use urandom::rng::MockRng;
let mut rng = MockRng::slice(&[1, 2, 13, 42]);
assert_eq!(rng.next_u64(), 1);
assert_eq!(rng.next_u64(), 2);
assert_eq!(rng.next_u64(), 13);
assert_eq!(rng.next_u64(), 42);
// Any further calls to the MockRng will panic unless the underlying iterator is unbounded.
sourceimpl MockRng<Repeat<u64>>
impl MockRng<Repeat<u64>>
sourcepub fn repeat(value: u64) -> Random<Self>ⓘNotable traits for Random<R>impl<R: Rng> Read for Random<R>
pub fn repeat(value: u64) -> Random<Self>ⓘNotable traits for Random<R>impl<R: Rng> Read for Random<R>
Produces the same random number repeatedly as the underlying random number generator.
use urandom::rng::MockRng;
let mut rng = MockRng::repeat(42);
assert_eq!(rng.next_u64(), 42);
assert_eq!(rng.next_u64(), 42);
assert_eq!(rng.next_u64(), 42);
Trait Implementations
sourceimpl<I> Rng for MockRng<I>where
I: Iterator<Item = u64>,
impl<I> Rng for MockRng<I>where
I: Iterator<Item = u64>,
Auto Trait Implementations
impl<I> RefUnwindSafe for MockRng<I>where
I: RefUnwindSafe,
impl<I> Send for MockRng<I>where
I: Send,
impl<I> Sync for MockRng<I>where
I: Sync,
impl<I> Unpin for MockRng<I>where
I: Unpin,
impl<I> UnwindSafe for MockRng<I>where
I: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more