File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 3
3
While Rust chooses how to capture variables on the fly mostly without type
4
4
annotation, this ambiguity is not allowed when writing functions. When
5
5
taking a closure as an input parameter, the closure's complete type must be
6
- annotated using one of a few ` traits ` . In order of decreasing restriction,
6
+ annotated using one of a few ` traits ` , and they're determined by what the
7
+ closure does with captured value. In order of decreasing restriction,
7
8
they are:
8
9
9
- * ` Fn ` : the closure captures by reference (` &T ` )
10
- * ` FnMut ` : the closure captures by mutable reference (` &mut T ` )
11
- * ` FnOnce ` : the closure captures by value (` T ` )
10
+ * ` Fn ` : the closure uses the captured value by reference (` &T ` )
11
+ * ` FnMut ` : the closure uses the captured value by mutable reference (` &mut T ` )
12
+ * ` FnOnce ` : the closure uses the captured value by value (` T ` )
12
13
13
14
On a variable-by-variable basis, the compiler will capture variables in the
14
15
least restrictive manner possible.
You can’t perform that action at this time.
0 commit comments