# Trait bitflags::__core::ops::IndexMut [−] [src]

    pub trait IndexMut<Idx>: Index<Idx> where Idx: ?Sized {
        fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
    }

The `IndexMut` trait is used to specify the functionality of indexing operations like `arr[idx]`, when used in a mutable context.

# Examples

A trivial implementation of `IndexMut`. When `Foo[Bar]` happens, it ends up calling `index_mut`, and therefore, `main` prints `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(&mut self, index: Idx) -> &mut Self::Output`

The method for the indexing (`Foo[Bar]`) operation

## Implementors

- `impl<A> IndexMut for VecDeque<A>`
- `impl<T> IndexMut for Vec<T>`
- `impl<T> IndexMut for Vec<T>`
- `impl<T> IndexMut for Vec<T>`
- `impl<T> IndexMut for Vec<T>`
- `impl<T> IndexMut for Vec<T>`
- `impl<T> IndexMut for Vec<T>`
- `impl<T> IndexMut for Vec<T>`
- `impl IndexMut for String`
- `impl IndexMut for String`
- `impl IndexMut for String`
- `impl IndexMut for String`
- `impl IndexMut for String`
- `impl IndexMut for String`
- `impl<T> IndexMut for [T]`
- `impl<T> IndexMut for [T]`
- `impl<T> IndexMut for [T]`
- `impl<T> IndexMut for [T]`
- `impl<T> IndexMut for [T]`
- `impl<T> IndexMut for [T]`
- `impl<T> IndexMut for [T]`
- `impl IndexMut for str`
- `impl IndexMut for str`
- `impl IndexMut for str`
- `impl IndexMut for str`
- `impl IndexMut for str`
- `impl IndexMut for str`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)