Trait std::ops::FnMut1.0.0 [] [src]

pub trait FnMut<Args>: FnOnce<Args> {
    extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
}

A version of the call operator that takes a mutable receiver.

Examples

Closures that mutably capture variables automatically implement this trait, which allows them to be invoked.

let mut x = 5;
{
    let mut square_x = || x *= x;
    square_x();
}
assert_eq!(x, 25);Run

Closures can also be passed to higher-level functions through a FnMut parameter (or a FnOnce parameter, which is a supertrait of FnMut).

fn do_twice<F>(mut func: F)
    where F: FnMut()
{
    func();
    func();
}

let mut x: usize = 1;
{
    let add_two_to_x = || x += 2;
    do_twice(add_two_to_x);
}

assert_eq!(x, 5);Run

Required Methods

Unstable (fn_traits #29625)

This is called when the call operator is used.

Implementors