Rust Systems & Tokio (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What are Closures in Rust and the three Closure Traits (`Fn`, `FnMut`, `FnOnce`)?
senior LevelMost AskedClosures & ScopeSystem Design
In Simple Words: Anonymous functions that can capture their enclosing environment:
FnOnce: Consumes captured variables by value (ownership moved). Can only be called once.FnMut: Mutates captured variables. Can be called multiple times.Fn: Borrows captured variables immutably. Pure read-only; can be called concurrently.