Struct proptest::sample::Selector [−][src]
A value for picking random values out of iterators.
This is, in a sense, a more flexible variant of
Index
in that it can operate on arbitrary
IntoIterator
values.
Initially, the selection is roughly uniform, with a very slight bias towards items earlier in the iterator.
Shrinking causes the selection to move toward items earlier in the iterator, ultimately settling on the very first, but this currently happens in a very haphazard way that may fail to find the earliest failing input.
Example
Generate a non-indexable collection and a value to pick out of it.
use proptest::prelude::*; proptest! { #[test] fn my_test( names in prop::collection::hash_set("[a-z]+", 10..20), selector in any::<prop::sample::Selector>() ) { println!("Selected name: {}", selector.select(&names)); // Test stuff... } }
Implementations
impl Selector
[src]
pub fn select<T: IntoIterator>(&self, it: T) -> T::Item
[src]
Pick a random element from iterable it
.
The selection is unaffected by the elements themselves, and is
dependent only on the actual length of it
.
it
is always iterated completely.
Panics
Panics if it
has no elements.
pub fn try_select<T: IntoIterator>(&self, it: T) -> Option<T::Item>
[src]
Pick a random element from iterable it
.
Returns None
if it
is empty.
The selection is unaffected by the elements themselves, and is
dependent only on the actual length of it
.
it
is always iterated completely.
Trait Implementations
impl Arbitrary for Selector
[src]
type Parameters = ()
The type of parameters that arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
. Read more
type Strategy = SelectorStrategy
fn arbitrary_with(_: ()) -> SelectorStrategy
[src]
fn arbitrary() -> Self::Strategy
[src]
impl Clone for Selector
[src]
fn clone(&self) -> Selector
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Selector
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,