Trait std::ops::IndexExperimental
[-]
[+]
[src]
pub trait Index<Index, Result> { fn index(&'a self, index: &Index) -> &'a Result; }
The Index
trait is used to specify the functionality of indexing operations
like arr[idx]
when used in an immutable context.
Example
A trivial implementation of Index
. When Foo[Foo]
happens, it ends up
calling index
, and therefore, main
prints Indexing!
.
#[deriving(Copy)] struct Foo; impl Index<Foo, Foo> for Foo { fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { println!("Indexing!"); self } } fn main() { Foo[Foo]; }
Required Methods
fn index(&'a self, index: &Index) -> &'a Result
The method for the indexing (Foo[Bar]
) operation
Implementors
impl<T> Index<uint, T> for [T]
impl<K: Hash<S> + Eq, Q: ?Sized, V, S, H: Hasher<S>> Index<Q, V> for HashMap<K, V, H> where Q: BorrowFrom<K> + Hash<S> + Eq
impl<K: Hash<S> + Eq, Q: ?Sized, V, S, H: Hasher<S>> Index<Q, V> for HashMap<K, V, H> where Q: BorrowFrom<K> + Hash<S> + Eq
impl Index<uint, bool> for Bitv
impl<K: Ord, Q, V> Index<Q, V> for BTreeMap<K, V>
impl<A> Index<uint, A> for RingBuf<A>
impl<T> Index<uint, T> for Vec<T>
impl<V> Index<uint, V> for VecMap<V>