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::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.

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

impl Arbitrary for Selector

type Parameters = ();
type Strategy = SelectorStrategy;
fn arbitrary_with(()) -> SelectorStrategy

impl Clone for Selector

fn clone(&self) -> Selector

impl Debug for Selector

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl Freeze for Selector

impl RefUnwindSafe for Selector

impl Send for Selector

impl Sync for Selector

impl Unpin for Selector

impl UnsafeUnpin for Selector

impl UnwindSafe for Selector

Blanket Implementations

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Selector where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Selector where ST: ?Sized, DT: ?Sized,

impl<T> Any for Selector where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Selector where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Selector where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Selector where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Selector

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Read<Exclusive, BecauseExclusive> for Selector where T: ?Sized,

impl<T> ToOwned for Selector where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Selector where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Selector where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Selector where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

impl<V, T> VZip<V> for Selector where V: MultiLane<T>,

fn vzip(self) -> V