Struct Selector
pub struct Selector { /* private fields */ }
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...
}
}
#
# fn main() { my_test(); }
Implementations
impl Selector
fn select<T: IntoIterator>(&self, it: T) -> T::ItemPick a random element from iterable
it.The selection is unaffected by the elements themselves, and is dependent only on the actual length of
it.itis always iterated completely.Panics
Panics if
ithas no elements.fn try_select<T: IntoIterator>(&self, it: T) -> Option<T::Item>Pick a random element from iterable
it.Returns
Noneifitis empty.The selection is unaffected by the elements themselves, and is dependent only on the actual length of
it.itis always iterated completely.
Trait Implementations
impl Arbitrary for Selector
type Parameters = ();type Strategy = SelectorStrategy;fn arbitrary_with(()) -> SelectorStrategy
impl Clone for Selector
fn clone(&self) -> Self
impl Debug for Selector
fn fmt(&self, f: &mut Formatter<'_>) -> Result