Skip to main content

Index

Trait Index 

Source
pub trait Index {
    type Ref;

    // Required method
    fn get(&self, index: usize) -> Self::Ref;

    // Provided methods
    fn last(&self) -> Option<Self::Ref>
       where Self: Len { ... }
    fn index_iter(&self) -> IterOwn<&Self>  { ... }
    fn into_index_iter(self) -> IterOwn<Self> 
       where Self: Sized { ... }
}
Expand description

A type that can be accessed by usize but without borrowing self.

This can be useful for types which include their own lifetimes, and which wish to express that their reference has the same lifetime. In the GAT Index, the Ref<'_> lifetime would be tied to &self.

This trait may be challenging to implement for owning containers, for example Vec<_>, which would need their Ref type to depend on the lifetime of the &self borrow in the get() function.

§Performance

A call to get(index) will attempt to access member slices at index, and as these could panic the optimizer cannot eliminate them even if you do not then go on to examine the values. If you plan to access a field (for tuples or structs) or variant match (for enums) you should perform this before calling get(index) when able.

Required Associated Types§

Source

type Ref

The type returned by the get method.

This trait is most often implemented for lifetimed containers, and the Ref type will have a lifetime that depends on that of the containers, rather than &self.

Required Methods§

Source

fn get(&self, index: usize) -> Self::Ref

Returns the reference type for location index.

Implementations should most likely be marked #[inline(always)]. If possible, avoid the potential to panic in these implementations, as this prevents Rust/LLVM from eliding the test even if the return value is not actually consumed.

Provided Methods§

Source

fn last(&self) -> Option<Self::Ref>
where Self: Len,

Source

fn index_iter(&self) -> IterOwn<&Self>

Converts &self into an iterator.

This has an awkward name to avoid collision with iter(), which may also be implemented.

Source

fn into_index_iter(self) -> IterOwn<Self>
where Self: Sized,

Converts self into an iterator.

This has an awkward name to avoid collision with into_iter(), which may also be implemented.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, A> Index for &'a (A,)
where &'a A: Index,

Source§

type Ref = (<&'a A as Index>::Ref,)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B> Index for &'a (A, B)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C> Index for &'a (A, B, C)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C, D> Index for &'a (A, B, C, D)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref, <&'a D as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C, D, E> Index for &'a (A, B, C, D, E)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref, <&'a D as Index>::Ref, <&'a E as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C, D, E, F> Index for &'a (A, B, C, D, E, F)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref, <&'a D as Index>::Ref, <&'a E as Index>::Ref, <&'a F as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C, D, E, F, G> Index for &'a (A, B, C, D, E, F, G)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref, <&'a D as Index>::Ref, <&'a E as Index>::Ref, <&'a F as Index>::Ref, <&'a G as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C, D, E, F, G, H> Index for &'a (A, B, C, D, E, F, G, H)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref, <&'a D as Index>::Ref, <&'a E as Index>::Ref, <&'a F as Index>::Ref, <&'a G as Index>::Ref, <&'a H as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C, D, E, F, G, H, I> Index for &'a (A, B, C, D, E, F, G, H, I)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref, <&'a D as Index>::Ref, <&'a E as Index>::Ref, <&'a F as Index>::Ref, <&'a G as Index>::Ref, <&'a H as Index>::Ref, <&'a I as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, A, B, C, D, E, F, G, H, I, J> Index for &'a (A, B, C, D, E, F, G, H, I, J)

Source§

type Ref = (<&'a A as Index>::Ref, <&'a B as Index>::Ref, <&'a C as Index>::Ref, <&'a D as Index>::Ref, <&'a E as Index>::Ref, <&'a F as Index>::Ref, <&'a G as Index>::Ref, <&'a H as Index>::Ref, <&'a I as Index>::Ref, <&'a J as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, T> Index for &'a [T]

Source§

type Ref = &'a T

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<'a, T> Index for &'a Vec<T>

Source§

type Ref = &'a T

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index> Index for (A,)

Source§

type Ref = (<A as Index>::Ref,)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index> Index for (A, B)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index> Index for (A, B, C)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index, D: Index> Index for (A, B, C, D)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref, <D as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index, D: Index, E: Index> Index for (A, B, C, D, E)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref, <D as Index>::Ref, <E as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index, D: Index, E: Index, F: Index> Index for (A, B, C, D, E, F)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref, <D as Index>::Ref, <E as Index>::Ref, <F as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index, D: Index, E: Index, F: Index, G: Index> Index for (A, B, C, D, E, F, G)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref, <D as Index>::Ref, <E as Index>::Ref, <F as Index>::Ref, <G as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index, D: Index, E: Index, F: Index, G: Index, H: Index> Index for (A, B, C, D, E, F, G, H)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref, <D as Index>::Ref, <E as Index>::Ref, <F as Index>::Ref, <G as Index>::Ref, <H as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index, D: Index, E: Index, F: Index, G: Index, H: Index, I: Index> Index for (A, B, C, D, E, F, G, H, I)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref, <D as Index>::Ref, <E as Index>::Ref, <F as Index>::Ref, <G as Index>::Ref, <H as Index>::Ref, <I as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<A: Index, B: Index, C: Index, D: Index, E: Index, F: Index, G: Index, H: Index, I: Index, J: Index> Index for (A, B, C, D, E, F, G, H, I, J)

Source§

type Ref = (<A as Index>::Ref, <B as Index>::Ref, <C as Index>::Ref, <D as Index>::Ref, <E as Index>::Ref, <F as Index>::Ref, <G as Index>::Ref, <H as Index>::Ref, <I as Index>::Ref, <J as Index>::Ref)

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<T: Copy> Index for [T]

Source§

type Ref = T

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<T: Copy> Index for Vec<T>

Source§

type Ref = T

Source§

fn get(&self, index: usize) -> Self::Ref

Source§

impl<T: Copy, const N: usize> Index for [T; N]

Source§

type Ref = T

Source§

fn get(&self, index: usize) -> Self::Ref

Implementors§

Source§

impl<'a> Index for Discriminant<&'a [u8], &'a [u64]>

Source§

type Ref = (u8, u64)

Source§

impl<'a, BC: Len + IndexAs<u64>> Index for &'a Strings<BC, Vec<u8>>

Source§

type Ref = &'a [u8]

Source§

impl<'a, BC: Len + IndexAs<u64>> Index for Strings<BC, &'a [u8]>

Source§

type Ref = &'a [u8]

Source§

impl<'a, CC> Index for &'a Empties<CC>

Source§

type Ref = &'a ()

Source§

impl<'a, S> Index for &'a Slice<S>
where &'a S: Index,

Source§

type Ref = <&'a S as Index>::Ref

Source§

impl<'a, SC, TC, CC, VC, WC> Index for &'a Results<SC, TC, CC, VC, WC>
where &'a SC: Index, &'a TC: Index, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: IndexAs<u64>,

Source§

impl<'a, TC> Index for &'a Repeats<TC>
where &'a TC: Index,

Source§

impl<'a, TC, BC: Len + IndexAs<u64>> Index for &'a Vecs<TC, BC>

Source§

impl<'a, TC, BC: IndexAs<u64> + Len> Index for &'a Trees<TC, BC>

Source§

impl<'a, TC, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: IndexAs<u64>> Index for &'a Options<TC, CC, VC, WC>
where &'a TC: Index,

Source§

impl<'a, TC, const N: u8> Index for &'a Lookbacks<TC, Vec<u8>, Vec<u64>, Vec<u64>, [u64; 2], N>
where &'a TC: Index,

Source§

impl<'a, const K: u64, CC> Index for &'a Fixeds<K, CC>

Source§

impl<BC: IndexAs<u64>, HC: IndexAs<u64>> Index for Strides<BC, HC>

Source§

impl<C: Index> Index for Boxed<C>

Source§

type Ref = Boxed<<C as Index>::Ref>

Source§

impl<CC> Index for Empties<CC>

Source§

impl<CV: IndexAs<i64>> Index for &Isizes<CV>

Source§

impl<CV: IndexAs<i64>> Index for Isizes<CV>

Source§

impl<CV: IndexAs<u32>> Index for &Chars<CV>

Source§

impl<CV: IndexAs<u32>> Index for Chars<CV>

Source§

impl<CV: IndexAs<u64>> Index for &Usizes<CV>

Source§

impl<CV: IndexAs<u64>> Index for Usizes<CV>

Source§

impl<CV: IndexAs<[u8; 16]>> Index for &I128s<CV>

Source§

impl<CV: IndexAs<[u8; 16]>> Index for &U128s<CV>

Source§

impl<CV: IndexAs<[u8; 16]>> Index for I128s<CV>

Source§

impl<CV: IndexAs<[u8; 16]>> Index for U128s<CV>

Source§

impl<S: Index> Index for Slice<S>

Source§

type Ref = <S as Index>::Ref

Source§

impl<SC, TC, CC, VC, WC> Index for Results<SC, TC, CC, VC, WC>
where SC: Index, TC: Index, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: IndexAs<u64>,

Source§

type Ref = Result<<SC as Index>::Ref, <TC as Index>::Ref>

Source§

impl<SC: IndexAs<u64>, NC: IndexAs<u32>> Index for &Durations<SC, NC>

Source§

impl<SC: IndexAs<u64>, NC: IndexAs<u32>> Index for Durations<SC, NC>

Source§

impl<TC: Copy, BC: Len + IndexAs<u64>> Index for Vecs<TC, BC>

Source§

type Ref = Slice<TC>

Source§

impl<TC: Index + Copy, BC: IndexAs<u64> + Len + Copy> Index for Trees<TC, BC>

Source§

type Ref = TreesRef<TC, BC>

Source§

impl<TC: Index, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: IndexAs<u64>> Index for Repeats<TC, CC, VC, WC>

Source§

type Ref = <TC as Index>::Ref

Source§

impl<TC: Index, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: IndexAs<u64>> Index for Options<TC, CC, VC, WC>

Source§

type Ref = Option<<TC as Index>::Ref>

Source§

impl<TC: Index, VC: IndexAs<u8>, CC: IndexAs<u64> + Len, RC: IndexAs<u64> + Len, WC: IndexAs<u64>, const N: u8> Index for Lookbacks<TC, VC, CC, RC, WC, N>

Source§

type Ref = <TC as Index>::Ref

Source§

impl<VC: Len + IndexAs<u64>, TC: IndexAs<u64>> Index for &Bools<VC, TC>

Source§

impl<VC: Len + IndexAs<u64>, TC: IndexAs<u64>> Index for Bools<VC, TC>

Source§

impl<const K: u64, CC> Index for Fixeds<K, CC>