Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Fn traits

The three traits that say how often a closure can be called and what it may do to its captures.

FnOnce closures can be called at least once, FnMut ones repeatedly with mutable access to captures, Fn ones repeatedly through a shared reference; every Fn is FnMut, and every FnMut is FnOnce.

Examples

  • fn run_twice<F: Fn()>(task: F) rejects || laps += 1 with E0525: that closure changes a capture, so it is only FnMut.

  • A move closure whose body does let sent = receipt; is only FnOnce, so calling it twice fails with E0382.

Read the full section →