[][src]Struct index_ext::int::TryIndex

#[repr(transparent)]pub struct TryIndex<T>(pub T);

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

Trait Implementations

impl<T: Clone> Clone for TryIndex<T>[src]

impl<T: Copy> Copy for TryIndex<T>[src]

impl<T: Debug> Debug for TryIndex<T>[src]

impl<T: Default> Default for TryIndex<T>[src]

impl<T: Eq> Eq for TryIndex<T>[src]

impl<T: Hash> Hash for TryIndex<T>[src]

impl<T, U> Index<TryIndex<T>> for [U] where
    T: TryInto<usize> + IndexSealed,
    T::Error: Into<TryFromIntError>, 
[src]

type Output = U

The returned type after indexing.

impl<T, U> IndexMut<TryIndex<T>> for [U] where
    T: TryInto<usize> + IndexSealed,
    T::Error: Into<TryFromIntError>, 
[src]

impl<T, U> IntSliceIndex<[U]> for TryIndex<T> where
    T: TryInto<usize>,
    T::Error: Into<TryFromIntError>, 
[src]

impl<T: Ord> Ord for TryIndex<T>[src]

impl<T: PartialEq> PartialEq<TryIndex<T>> for TryIndex<T>[src]

impl<T: PartialOrd> PartialOrd<TryIndex<T>> for TryIndex<T>[src]

impl<T> StructuralEq for TryIndex<T>[src]

impl<T> StructuralPartialEq for TryIndex<T>[src]

Auto Trait Implementations

impl<T> Send for TryIndex<T> where
    T: Send

impl<T> Sync for TryIndex<T> where
    T: Sync

impl<T> Unpin for TryIndex<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.