Trait std::ops::IndexStable
[-]
[+]
[src]
pub trait Index<Index> where Index: ?Sized {
type Output;
fn index(&'a self, index: &Index) -> &'a <Self as Index<Index>>::Output;
}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[Bar] happens, it ends up
calling index, and therefore, main prints Indexing!.
use std::ops::Index; #[derive(Copy)] struct Foo; struct Bar; impl Index<Bar> for Foo { type Output = Foo; fn index<'a>(&'a self, _index: &Bar) -> &'a Foo { println!("Indexing!"); self } } fn main() { Foo[Bar]; }
Associated Types
Required Methods
fn index(&'a self, index: &Index) -> &'a <Self as Index<Index>>::Output
The method for the indexing (Foo[Bar]) operation
Implementors
impl<T> Index<usize> for [T]impl<T> Index<Range<usize>> for [T]impl<T> Index<RangeTo<usize>> for [T]impl<T> Index<RangeFrom<usize>> for [T]impl<T> Index<RangeFull> for [T]impl<'a, T> Index<Range<usize>> for Iter<'a, T>impl<'a, T> Index<RangeTo<usize>> for Iter<'a, T>impl<'a, T> Index<RangeFrom<usize>> for Iter<'a, T>impl<'a, T> Index<RangeFull> for Iter<'a, T>impl<'a, T> Index<Range<usize>> for IterMut<'a, T>impl<'a, T> Index<RangeTo<usize>> for IterMut<'a, T>impl<'a, T> Index<RangeFrom<usize>> for IterMut<'a, T>impl<'a, T> Index<RangeFull> for IterMut<'a, T>impl Index<Range<usize>> for strimpl Index<RangeTo<usize>> for strimpl Index<RangeFrom<usize>> for strimpl Index<RangeFull> for strimpl Index<usize> for Bitvimpl<K, Q, V> Index<Q> for BTreeMap<K, V> where K: Ord, Q: BorrowFrom<K>, Q: Ord, Q: ?Sizedimpl<A> Index<usize> for RingBuf<A>impl Index<Range<usize>> for Stringimpl Index<RangeTo<usize>> for Stringimpl Index<RangeFrom<usize>> for Stringimpl Index<RangeFull> for Stringimpl<T> Index<usize> for Vec<T>impl<T> Index<Range<usize>> for Vec<T>impl<T> Index<RangeTo<usize>> for Vec<T>impl<T> Index<RangeFrom<usize>> for Vec<T>impl<T> Index<RangeFull> for Vec<T>impl<V> Index<usize> for VecMap<V>impl Index<RangeFull> for OsStringimpl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S> where K: Eq + Hash<H>, Q: Eq + Hash<H> + BorrowFrom<K>, S: HashState<Hasher=H>, H: Hasher<Output=u64>impl<K, Q: ?Sized, V, S, H> Index<Q> for HashMap<K, V, S> where K: Eq + Hash<H>, Q: Eq + Hash<H> + BorrowFrom<K>, S: HashState<Hasher=H>, H: Hasher<Output=u64>