Trait core::ops::IndexUnstable
[-]
[+]
[src]
pub trait Index<Index: ?Sized> {
type Output: ?Sized;
fn index<'a>(&'a self, index: &Index) -> &'a 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[Foo] happens, it ends up
calling index, and therefore, main prints Indexing!.
#![feature(associated_types)] use std::ops::Index; #[derive(Copy)] struct Foo; impl Index<Foo> for Foo { type Output = Foo; fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { println!("Indexing!"); self } } fn main() { Foo[Foo]; }
Associated Types
type Output: ?Sized
Required Methods
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<FullRange> 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<FullRange> 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<FullRange> for IterMut<'a, T>impl Index<Range<usize>> for strimpl Index<RangeTo<usize>> for strimpl Index<RangeFrom<usize>> for strimpl Index<FullRange> for str