@@ -19,16 +19,16 @@ use mem;
19
19
/// A thread local storage key which owns its contents.
20
20
///
21
21
/// This key uses the fastest possible implementation available to it for the
22
- /// target platform. It is instantiated with the `thread_local!` macro and the
23
- /// primary method is the `with` method.
22
+ /// target platform. It is instantiated with the [ `thread_local!`] macro and the
23
+ /// primary method is the [ `with`] method.
24
24
///
25
- /// The `with` method yields a reference to the contained value which cannot be
25
+ /// The [ `with`] method yields a reference to the contained value which cannot be
26
26
/// sent across threads or escape the given closure.
27
27
///
28
28
/// # Initialization and Destruction
29
29
///
30
- /// Initialization is dynamically performed on the first call to `with()`
31
- /// within a thread, and values that implement `Drop` get destructed when a
30
+ /// Initialization is dynamically performed on the first call to [ `with`]
31
+ /// within a thread, and values that implement [ `Drop`] get destructed when a
32
32
/// thread exits. Some caveats apply, which are explained below.
33
33
///
34
34
/// # Examples
@@ -77,6 +77,10 @@ use mem;
77
77
/// 3. On macOS, initializing TLS during destruction of other TLS slots can
78
78
/// sometimes cancel *all* destructors for the current thread, whether or not
79
79
/// the slots have already had their destructors run or not.
80
+ ///
81
+ /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
82
+ /// [`thread_local!`]: ../../std/macro.thread_local.html
83
+ /// [`Drop`]: ../../std/ops/trait.Drop.html
80
84
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
81
85
pub struct LocalKey < T : ' static > {
82
86
// This outer `LocalKey<T>` type is what's going to be stored in statics,
@@ -106,7 +110,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
106
110
}
107
111
}
108
112
109
- /// Declare a new thread local storage key of type `std::thread::LocalKey`.
113
+ /// Declare a new thread local storage key of type [ `std::thread::LocalKey`] .
110
114
///
111
115
/// # Syntax
112
116
///
@@ -124,8 +128,10 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
124
128
/// # fn main() {}
125
129
/// ```
126
130
///
127
- /// See [LocalKey documentation]( thread/struct. LocalKey.html) for more
131
+ /// See [LocalKey documentation][`std:: thread:: LocalKey`] for more
128
132
/// information.
133
+ ///
134
+ /// [`std::thread::LocalKey`]: ../std/thread/struct.LocalKey.html
129
135
#[ macro_export]
130
136
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
131
137
#[ allow_internal_unstable]
@@ -195,11 +201,13 @@ macro_rules! __thread_local_inner {
195
201
#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
196
202
pub enum LocalKeyState {
197
203
/// All keys are in this state whenever a thread starts. Keys will
198
- /// transition to the `Valid` state once the first call to `with` happens
204
+ /// transition to the `Valid` state once the first call to [ `with`] happens
199
205
/// and the initialization expression succeeds.
200
206
///
201
207
/// Keys in the `Uninitialized` state will yield a reference to the closure
202
- /// passed to `with` so long as the initialization routine does not panic.
208
+ /// passed to [`with`] so long as the initialization routine does not panic.
209
+ ///
210
+ /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
203
211
Uninitialized ,
204
212
205
213
/// Once a key has been accessed successfully, it will enter the `Valid`
@@ -208,15 +216,19 @@ pub enum LocalKeyState {
208
216
/// `Destroyed` state.
209
217
///
210
218
/// Keys in the `Valid` state will be guaranteed to yield a reference to the
211
- /// closure passed to `with`.
219
+ /// closure passed to [`with`].
220
+ ///
221
+ /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
212
222
Valid ,
213
223
214
224
/// When a thread exits, the destructors for keys will be run (if
215
225
/// necessary). While a destructor is running, and possibly after a
216
226
/// destructor has run, a key is in the `Destroyed` state.
217
227
///
218
228
/// Keys in the `Destroyed` states will trigger a panic when accessed via
219
- /// `with`.
229
+ /// [`with`].
230
+ ///
231
+ /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
220
232
Destroyed ,
221
233
}
222
234
@@ -283,23 +295,26 @@ impl<T: 'static> LocalKey<T> {
283
295
/// Query the current state of this key.
284
296
///
285
297
/// A key is initially in the `Uninitialized` state whenever a thread
286
- /// starts. It will remain in this state up until the first call to `with`
298
+ /// starts. It will remain in this state up until the first call to [ `with`]
287
299
/// within a thread has run the initialization expression successfully.
288
300
///
289
301
/// Once the initialization expression succeeds, the key transitions to the
290
- /// `Valid` state which will guarantee that future calls to `with` will
302
+ /// `Valid` state which will guarantee that future calls to [ `with`] will
291
303
/// succeed within the thread.
292
304
///
293
305
/// When a thread exits, each key will be destroyed in turn, and as keys are
294
306
/// destroyed they will enter the `Destroyed` state just before the
295
307
/// destructor starts to run. Keys may remain in the `Destroyed` state after
296
308
/// destruction has completed. Keys without destructors (e.g. with types
297
- /// that are `Copy`), may never enter the `Destroyed` state.
309
+ /// that are [ `Copy`] ), may never enter the `Destroyed` state.
298
310
///
299
311
/// Keys in the `Uninitialized` state can be accessed so long as the
300
312
/// initialization does not panic. Keys in the `Valid` state are guaranteed
301
313
/// to be able to be accessed. Keys in the `Destroyed` state will panic on
302
- /// any call to `with`.
314
+ /// any call to [`with`].
315
+ ///
316
+ /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
317
+ /// [`Copy`]: ../../std/marker/trait.Copy.html
303
318
#[ unstable( feature = "thread_local_state" ,
304
319
reason = "state querying was recently added" ,
305
320
issue = "27716" ) ]
0 commit comments