Struct Index
pub struct Index(/* private field */);
A stand-in for an index into a slice or similar collection or conceptually similar things.
At the lowest level, Index is a mechanism for generating usize values
in the range [0..N), for some N whose value is not known until it is
needed. (Contrast with using 0..N itself as a strategy, where you need to
know N when you define the strategy.)
For any upper bound, the actual index produced by an Index is the same no
matter how many times it is used. Different upper bounds will produce
different but not independent values.
Shrinking will cause the index to binary search through the underlying collection(s) it is used to sample.
Note that Index cannot currently be used as a slice index (e.g.,
slice[index]) due to the trait coherence rules.
Example
If the collection itself being indexed is itself generated by a strategy,
you can make separately define that strategy and a strategy generating one
or more Indexes and then join the two after input generation, avoiding a
call to prop_flat_map().
use *;
proptest!
#
#
Implementations
impl Index
fn index(&self, size: usize) -> usizeReturn the real index that would be used to index a collection of size
size.Panics
Panics if
size == 0.fn get<'a, T>(&self, slice: &'a [T]) -> &'a TReturn a reference to the element in
slicethat thisIndexrefers to.A shortcut for
&slice[index.index(slice.len())].fn get_mut<'a, T>(&self, slice: &'a mut [T]) -> &'a mut TReturn a mutable reference to the element in
slicethat thisIndexrefers to.A shortcut for
&mut slice[index.index(slice.len())].
Trait Implementations
impl Arbitrary for Index
type Parameters = ();type Strategy = IndexStrategy;fn arbitrary_with(()) -> IndexStrategy
impl AsRef<Index> for Index
fn as_ref(&self) -> &Index
impl Clone for Index
fn clone(&self) -> Self
impl Copy for Index
impl Debug for Index
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl Freeze for Index
impl RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl UnsafeUnpin for Index
impl UnwindSafe for Index
Blanket Implementations
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Index
where
ST: ?Sized,
DT: ?Sized,
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Index
where
ST: ?Sized,
DT: ?Sized,
impl<T> Any for Index
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Index
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Index
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Index
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Index
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Read<Exclusive, BecauseExclusive> for Index
where
T: ?Sized,
impl<T> ToOwned for Index
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Index
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Index
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Index
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 Index
where
V: MultiLane<T>,
fn vzip(self) -> V