Struct Selector
struct Selector { ... }
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!
#
#
Implementations
impl Selector
fn select<T: IntoIterator>(self: &Self, it: T) -> <T as >::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: &Self, it: T) -> Option<<T as >::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.
impl Arbitrary for crate::sample::Selector
fn arbitrary_with(_: ()) -> SelectorStrategy
impl Clone for Selector
fn clone(self: &Self) -> Selector
impl Debug for Selector
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Freeze for Selector
impl RefUnwindSafe for Selector
impl Send for Selector
impl Sync for Selector
impl Unpin for Selector
impl UnwindSafe for Selector
impl<T> Any for Selector
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Selector
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Selector
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Selector
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Selector
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Selector
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Selector
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Selector
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Selector
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<V, T> VZip for Selector
fn vzip(self: Self) -> V