std::ops::FnMut
Trait std::ops::FnMut
#[lang = "fn_mut"] 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);
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; {