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.

Required Associated Types§

Source

type Ref

The type returned by the get method.

Notably, this does not vary with lifetime, and will not depend on the lifetime of &self.

Required Methods§

Source

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

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

Implementors§

Source§

impl Index for Strides<&[u64], &u64>

Source§

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

Source§

type Ref = &'a str

Source§

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

Source§

type Ref = &'a str

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: CopyAs<u64>,

Source§

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

Source§

impl<'a, TC, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: CopyAs<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>, N>
where &'a TC: Index,

Source§

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

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: CopyAs<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<TC: Copy, BC: Len + IndexAs<u64>> Index for Vecs<TC, BC>

Source§

type Ref = Slice<TC>

Source§

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

Source§

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

Source§

impl<TC: Index, VC: Index<Ref = u8>, const N: u8> Index for Lookbacks<TC, VC, N>

Source§

type Ref = <TC as Index>::Ref

Source§

impl<TC: Index, const N: u8> Index for Repeats<TC, N>

Source§

type Ref = <TC as Index>::Ref

Source§

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

Source§

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

Source§

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