# Trait std::convert::AsMut 1.0.0 [−] [src]

    pub trait AsMut<T> where
        T: ?Sized, {
        fn as_mut(&mut self) -> &mut T;
    }

A cheap, mutable reference-to-mutable reference conversion.

This trait is similar to `AsRef` but used for converting between mutable references.

Note: this trait must not fail. If the conversion can fail, use a dedicated method which returns an `Option<T>` or a `Result<T, E>`.

# Generic Implementations

- `AsMut` auto-dereferences if the inner type is a reference or a mutable reference (e.g.: `foo.as_ref()` will work the same if `foo` has type `&mut Foo` or `&&mut Foo`)

# Examples

`Box<T>` implements `AsMut<T>`:

    fn add_one<T: AsMut<u64>>(num: &mut T) {
        *num.as_mut() += 1;
    }

    let mut boxed_num = Box::new(0);
    add_one(&mut boxed_num);
    assert_eq!(*boxed_num, 1);Run

## Required Methods

### `fn as_mut(&mut self) -> &mut T`

Performs the conversion.

## Implementors

- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:9177) => core/5e4b76f::array[0]::{{impl}}[354]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8681) => core/5e4b76f::array[0]::{{impl}}[178]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8402) => core/5e4b76f::array[0]::{{impl}}[79]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:9146) => core/5e4b76f::array[0]::{{impl}}[343]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8805) => core/5e4b76f::array[0]::{{impl}}[222]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8650) => core/5e4b76f::array[0]::{{impl}}[167]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8960) => core/5e4b76f::array[0]::{{impl}}[277]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8898) => core/5e4b76f::array[0]::{{impl}}[255]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8216) => core/5e4b76f::array[0]::{{impl}}[13]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:9084) => core/5e4b76f::array[0]::{{impl}}[321]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8526) => core/5e4b76f::array[0]::{{impl}}[123]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:9053) => core/5e4b76f::array[0]::{{impl}}[310]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8433) => core/5e4b76f::array[0]::{{impl}}[90]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8557) => core/5e4b76f::array[0]::{{impl}}[134]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8929) => core/5e4b76f::array[0]::{{impl}}[266]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8774) => core/5e4b76f::array[0]::{{impl}}[211]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8464) => core/5e4b76f::array[0]::{{impl}}[101]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8867) => core/5e4b76f::array[0]::{{impl}}[244]::{{initializer}}[0] }, Slice([])) }]`
- `impl<'a, T, U> AsMut<U> for &'a mut T where
  T: AsMut<U> + ?Sized,
  U: ?Sized,`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8743) => core/5e4b76f::array[0]::{{impl}}[200]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8836) => core/5e4b76f::array[0]::{{impl}}[233]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:9022) => core/5e4b76f::array[0]::{{impl}}[299]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8371) => core/5e4b76f::array[0]::{{impl}}[68]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8278) => core/5e4b76f::array[0]::{{impl}}[35]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:9115) => core/5e4b76f::array[0]::{{impl}}[332]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8991) => core/5e4b76f::array[0]::{{impl}}[288]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8619) => core/5e4b76f::array[0]::{{impl}}[156]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8340) => core/5e4b76f::array[0]::{{impl}}[57]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8247) => core/5e4b76f::array[0]::{{impl}}[24]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8588) => core/5e4b76f::array[0]::{{impl}}[145]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8712) => core/5e4b76f::array[0]::{{impl}}[189]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8185) => core/5e4b76f::array[0]::{{impl}}[2]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8309) => core/5e4b76f::array[0]::{{impl}}[46]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T; Const { ty: usize, val: Unevaluated(DefId { krate: CrateNum(1), node: DefIndex(1:8495) => core/5e4b76f::array[0]::{{impl}}[112]::{{initializer}}[0] }, Slice([])) }]`
- `impl<T> AsMut<[T]> for [T]`
- `impl<T> AsMut<[T]> for Vec<T>`
- `impl<T> AsMut<T> for Box<T> where
  T: ?Sized,`
- `impl<T> AsMut<Vec<T>> for Vec<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`)