File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,24 @@ impl ScopeData {
107
107
/// a.push(4);
108
108
/// assert_eq!(x, a.len());
109
109
/// ```
110
+ ///
111
+ /// # Lifetimes
112
+ ///
113
+ /// Scoped threads involve two lifetimes: `'scope` and `'env`.
114
+ ///
115
+ /// The `'scope` lifetime represents the lifetime of the scope itself.
116
+ /// That is: the time during which new scoped threads may be spawned,
117
+ /// and also the time during which they might still be running.
118
+ /// Once this lifetime ends, all scoped threads are joined.
119
+ /// This lifetime starts within the `scope` function, before `f` (the argument to `scope`) starts.
120
+ /// It ends after `f` returns and all scoped threads have been joined, but before `scope` returns.
121
+ ///
122
+ /// The `'env` lifetime represents the lifetime of whatever is borrowed by the scoped threads.
123
+ /// This lifetime must outlast the call to `scope`, and thus cannot be smaller than `'scope`.
124
+ /// It can be as small as the call to `scope`, meaning that anything that outlives this call,
125
+ /// such as local variables defined right before the scope, can be borrowed by the scoped threads.
126
+ ///
127
+ /// The `'env: 'scope` bound is part of the definition of the `Scope` type.
110
128
#[ track_caller]
111
129
pub fn scope < ' env , F , T > ( f : F ) -> T
112
130
where
You can’t perform that action at this time.
0 commit comments