File tree 1 file changed +17
-5
lines changed
1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -945,18 +945,30 @@ mod mod_keyword {}
945
945
/// `move` converts any variables captured by reference or mutable reference
946
946
/// to owned by value variables.
947
947
///
948
- /// Note: `move` closures may still implement [`Fn`] or [`FnMut`], even though
949
- /// they capture variables by `move`. This is because the traits implemented by
950
- /// a closure type are determined by *what* the closure does with captured
951
- /// values, not *how* it captures them.
952
- ///
953
948
/// ```rust
954
949
/// let capture = "hello";
955
950
/// let closure = move || {
956
951
/// println!("rust says {}", capture);
957
952
/// };
958
953
/// ```
959
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
+ ///
960
972
/// `move` is often used when [threads] are involved.
961
973
///
962
974
/// ```rust
You can’t perform that action at this time.
0 commit comments