# Trait core::ops::DerefMut 1.0.0 [−] [src]

    #[lang = "deref_mut"]
    pub trait DerefMut: Deref {
        fn deref_mut(&mut self) -> &mut Self::Target;
    }

The `DerefMut` trait is used to specify the functionality of dereferencing mutably like `*v = 1;`

`DerefMut` also enables '`Deref` coercions'.

# Examples

A struct with a single field which is modifiable via dereferencing the struct.

    use std::ops::{Deref, DerefMut};

    struct DerefMutExample<T> {
        value: T
    }

    impl<T> Deref for DerefMutExample<T> {
        type Target = T;

        fn deref(&self) -> &T {
            &self.value
        }
    }

    impl<T> DerefMut for DerefMutExample<T> {
        fn deref_mut(&mut self) -> &mut T {
            &mut self.value
        }
    }

    fn main() {
        let mut x = DerefMutExample { value: 'a' };
        *x = 'b';
        assert_eq!('b', *x);
    }Run

## Required Methods

### `fn deref_mut(&mut self) -> &mut Self::Target`

The method called to mutably dereference a value

## Implementors

- `impl<'a, T: ?Sized> DerefMut for &'a mut T`
- `impl<'b, T: ?Sized> DerefMut for RefMut<'b, T>`

# 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
+
  Collapse/expand all sections

## 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`)