trait

FnMut — callable with mutable access

A closure that updates captured state usually implements FnMut. The caller needs mutable access to the callable. Fn also satisfies FnMut, and FnMut satisfies FnOnce. The stable call syntax is f(), not direct invocation of unstable call_mut. Expected stdout (not executed): 1 2 Common mistake: Requiring Fn for a callback that must update captured state. Static Rust 2024 example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
F: FnMut() -> u32

Working Example

Example Snippetrust
fn sample(mut next: impl FnMut() -> u32) { println!("{} {}", next(), next()); }fn main() { let mut n=0; sample(|| { n+=1; n }); }
Rust Reference