#[repr(transparent)]pub struct TryIndex<T>(pub T);
Expand description
An indexing adaptor for TryInto
.
This transparent wrapper allows any type to function as an index as long as it is fallibly
convertible to a usize
. An indexing operation is successful if the conversion succeeds and
the resulting index is in bounds. Contrary to the simple integer types, the implementation of
get_unchecked
methods will not unsafely assume that the conversion itself can’t fail, only
that the resulting index is in-bounds.
Separating this from the main IndexType
solves a coherence problem that would occurs when
instantiating it with ranges: The standard library is permitted to add new impls of
TryInto<usize>
, for example even for Range<usize>
. Hence, these two impls would overlap
but we would like the first to have another return type than the second. The indirection
over this type means that our impls are only generic for TryIndex<T>
instead and do not
overlap.
Tuple Fields§
§0: T
Trait Implementations§
source§impl<T: Ord> Ord for TryIndex<T>
impl<T: Ord> Ord for TryIndex<T>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<T: PartialEq> PartialEq for TryIndex<T>
impl<T: PartialEq> PartialEq for TryIndex<T>
source§impl<T: PartialOrd> PartialOrd for TryIndex<T>
impl<T: PartialOrd> PartialOrd for TryIndex<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more