trait

FnOnce — callable that may consume captured values

FnOnce is the least restrictive callable bound: it permits consuming the closure and calling it once. A closure that moves a captured String out cannot be called again. A move closure can still implement Fn or FnMut if its body does not consume captured values. Expected stdout (not executed): Rust Common mistake: Assuming every move closure is FnOnce-only. Static Rust 2024 example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
F: FnOnce() -> T

Working Example

Example Snippetrust
fn take<T>(f: impl FnOnce() -> T) -> T { f() }fn main() { let name=String::from("Rust"); println!("{}", take(move || name)); }
Rust Reference