@@ -987,13 +987,13 @@ mod mod_keyword {}
987
987
/// Capture a [closure]'s environment by value.
988
988
///
989
989
/// `move` converts any variables captured by reference or mutable reference
990
- /// to owned by value variables .
990
+ /// to variables captured by value.
991
991
///
992
992
/// ```rust
993
- /// let capture = "hello" ;
994
- /// let closure = move || {
995
- /// println!("rust says {}", capture);
996
- /// };
993
+ /// let data = vec![1, 2, 3] ;
994
+ /// let closure = move || println!("captured {:?} by value", data);
995
+ ///
996
+ /// // data is no longer available, it is owned by the closure
997
997
/// ```
998
998
///
999
999
/// Note: `move` closures may still implement [`Fn`] or [`FnMut`], even though
@@ -1004,31 +1004,29 @@ mod mod_keyword {}
1004
1004
/// ```rust
1005
1005
/// fn create_fn() -> impl Fn() {
1006
1006
/// let text = "Fn".to_owned();
1007
- ///
1008
1007
/// move || println!("This is a: {}", text)
1009
1008
/// }
1010
1009
///
1011
1010
/// let fn_plain = create_fn();
1012
- ///
1013
1011
/// fn_plain();
1014
1012
/// ```
1015
1013
///
1016
1014
/// `move` is often used when [threads] are involved.
1017
1015
///
1018
1016
/// ```rust
1019
- /// let x = 5 ;
1017
+ /// let data = vec![1, 2, 3] ;
1020
1018
///
1021
1019
/// std::thread::spawn(move || {
1022
- /// println!("captured {} by value", x )
1020
+ /// println!("captured {:? } by value", data )
1023
1021
/// }).join().unwrap();
1024
1022
///
1025
- /// // x is no longer available
1023
+ /// // data was moved to the spawned thread, so we cannot use it here
1026
1024
/// ```
1027
1025
///
1028
1026
/// `move` is also valid before an async block.
1029
1027
///
1030
1028
/// ```rust
1031
- /// let capture = "hello";
1029
+ /// let capture = "hello".to_owned() ;
1032
1030
/// let block = async move {
1033
1031
/// println!("rust says {} from async block", capture);
1034
1032
/// };
0 commit comments