Trait core::ops::Index[src]

pub trait Index<Index, Result> {
    fn index(&self, index: &Index) -> Result;
}

The Index trait is used to specify the functionality of indexing operations like arr[idx].

Example

A trivial implementation of Index. When Foo[Foo] happens, it ends up calling index, and therefore, main prints Indexing!.

struct Foo; impl Index<Foo, Foo> for Foo { fn index(&self, _rhs: &Foo) -> Foo { println!("Indexing!"); *self } } fn main() { Foo[Foo]; }
struct Foo;

impl Index<Foo, Foo> for Foo {
    fn index(&self, _rhs: &Foo) -> Foo {
        println!("Indexing!");
        *self
    }
}

fn main() {
    Foo[Foo];
}

Required Methods

fn index(&self, index: &Index) -> Result

The method for the indexing (Foo[Bar]) operation

Implementors