Trait std::ops::IndexMut
[−]
[src]
pub trait IndexMut<Idx>: Index<Idx> where Idx: ?Sized {
fn index_mut(&'a mut self, index: Idx) -> &'a mut Self::Output;
}The IndexMut`IndexMuttrait is used to specify the functionality of indexing operations like` trait is used to specify the functionality of indexing
operations like arr[idx]`arr[idx]`, when used in a mutable context.
Examples
A trivial implementation of IndexMut`IndexMut. When`. When Foo[Bar]`Foo[Bar]happens, it ends up calling` happens, it ends up
calling index_mut`index_mut, and therefore,`, and therefore, main`mainprints` prints Indexing!`Indexing!`.
use std::ops::{Index, IndexMut}; #[derive(Copy, Clone)] struct Foo; struct Bar; impl Index<Bar> for Foo { type Output = Foo; fn index<'a>(&'a self, _index: Bar) -> &'a Foo { self } } impl IndexMut<Bar> for Foo { fn index_mut<'a>(&'a mut self, _index: Bar) -> &'a mut Foo { println!("Indexing!"); self } } fn main() { &mut Foo[Bar]; }
Required Methods
fn index_mut(&'a mut self, index: Idx) -> &'a mut Self::Output
The method for the indexing (Foo[Bar]`Foo[Bar]`) operation
Implementors
impl<T> IndexMut<usize> for [T]impl<T> IndexMut<Range<usize>> for [T]impl<T> IndexMut<RangeTo<usize>> for [T]impl<T> IndexMut<RangeFrom<usize>> for [T]impl<T> IndexMut<RangeFull> for [T]impl<T> IndexMut<usize> for Vec<T>impl<T> IndexMut<Range<usize>> for Vec<T>impl<T> IndexMut<RangeTo<usize>> for Vec<T>impl<T> IndexMut<RangeFrom<usize>> for Vec<T>impl<T> IndexMut<RangeFull> for Vec<T>impl<A> IndexMut<usize> for VecDeque<A>impl<V> IndexMut<usize> for VecMap<V>impl<'a, V> IndexMut<&'a usize> for VecMap<V>