File tree 1 file changed +18
-2
lines changed
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -943,8 +943,7 @@ mod mod_keyword {}
943
943
/// Capture a [closure]'s environment by value.
944
944
///
945
945
/// `move` converts any variables captured by reference or mutable reference
946
- /// to owned by value variables. The three [`Fn` trait]'s mirror the ways to capture
947
- /// variables, when `move` is used, the closures is represented by the `FnOnce` trait.
946
+ /// to owned by value variables.
948
947
///
949
948
/// ```rust
950
949
/// let capture = "hello";
@@ -953,6 +952,23 @@ mod mod_keyword {}
953
952
/// };
954
953
/// ```
955
954
///
955
+ /// Note: `move` closures may still implement [`Fn`] or [`FnMut`], even though
956
+ /// they capture variables by `move`. This is because the traits implemented by
957
+ /// a closure type are determined by *what* the closure does with captured
958
+ /// values, not *how* it captures them:
959
+ ///
960
+ /// ```rust
961
+ /// fn create_fn() -> impl Fn() {
962
+ /// let text = "Fn".to_owned();
963
+ ///
964
+ /// move || println!("This is a: {}", text)
965
+ /// }
966
+ ///
967
+ /// let fn_plain = create_fn();
968
+ ///
969
+ /// fn_plain();
970
+ /// ```
971
+ ///
956
972
/// `move` is often used when [threads] are involved.
957
973
///
958
974
/// ```rust
You can’t perform that action at this time.
0 commit comments