Trait core::ops::IndexMut 1.0.0
[−]
[src]
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
}The IndexMut trait is used to specify the functionality of indexing
operations like container[index], when used in a mutable context.
Examples
A trivial implementation of IndexMut for a type Foo. When &mut Foo[2]
happens, it ends up calling index_mut, and therefore, main prints
Mutable indexing with 2!.
use std::ops::{Index, IndexMut}; #[derive(Copy, Clone)] struct Foo; impl Index<usize> for Foo { type Output = Foo; fn index(&self, _index: usize) -> &Foo { self } } impl IndexMut<usize> for Foo { fn index_mut(&mut self, index: usize) -> &mut Foo { println!("Mutable indexing with {}!", index); self } } fn main() { &mut Foo[2]; }Run
Required Methods
fn index_mut(&mut self, index: Idx) -> &mut Self::Output
The method for the mutable indexing (container[index]) 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<RangeInclusive<usize>> for [T]impl<T> IndexMut<RangeToInclusive<usize>> for [T]impl IndexMut<Range<usize>> for strimpl IndexMut<RangeTo<usize>> for strimpl IndexMut<RangeFrom<usize>> for strimpl IndexMut<RangeFull> for strimpl IndexMut<RangeInclusive<usize>> for strimpl IndexMut<RangeToInclusive<usize>> for str