pub struct Selector { /* private fields */ }
Expand description
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§
Source§impl Selector
impl Selector
Sourcepub fn select<T: IntoIterator>(&self, it: T) -> T::Item
pub fn select<T: IntoIterator>(&self, it: T) -> T::Item
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.
Sourcepub fn try_select<T: IntoIterator>(&self, it: T) -> Option<T::Item>
pub fn try_select<T: IntoIterator>(&self, it: T) -> Option<T::Item>
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§
Source§impl Arbitrary for Selector
impl Arbitrary for Selector
Source§type Parameters = ()
type Parameters = ()
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.Source§type Strategy = SelectorStrategy
type Strategy = SelectorStrategy
Strategy
used to generate values of type Self
.Source§fn arbitrary_with(_: ()) -> SelectorStrategy
fn arbitrary_with(_: ()) -> SelectorStrategy
Auto Trait Implementations§
impl Freeze for Selector
impl RefUnwindSafe for Selector
impl Send for Selector
impl Sync for Selector
impl Unpin for Selector
impl UnwindSafe for Selector
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 368 bytes