@@ -252,6 +252,19 @@ impl<T: 'static> LocalKey<T> {
252
252
/// This function will `panic!()` if the key currently has its
253
253
/// destructor running, and it **may** panic if the destructor has
254
254
/// previously been run for this thread.
255
+ ///
256
+ /// # Examples
257
+ ///
258
+ /// ```
259
+ /// thread_local! {
260
+ /// pub static STATIC: String = String::from("I am");
261
+ /// }
262
+ ///
263
+ /// assert_eq!(
264
+ /// STATIC.with(|original_value| format!("{original_value} initialized")),
265
+ /// "I am initialized",
266
+ /// );
267
+ /// ```
255
268
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
256
269
pub fn with < F , R > ( & ' static self , f : F ) -> R
257
270
where
@@ -273,6 +286,19 @@ impl<T: 'static> LocalKey<T> {
273
286
///
274
287
/// This function will still `panic!()` if the key is uninitialized and the
275
288
/// key's initializer panics.
289
+ ///
290
+ /// # Examples
291
+ ///
292
+ /// ```
293
+ /// thread_local! {
294
+ /// pub static STATIC: String = String::from("I am");
295
+ /// }
296
+ ///
297
+ /// assert_eq!(
298
+ /// STATIC.try_with(|original_value| format!("{original_value} initialized")),
299
+ /// Ok(String::from("I am initialized")),
300
+ /// );
301
+ /// ```
276
302
#[ stable( feature = "thread_local_try_with" , since = "1.26.0" ) ]
277
303
#[ inline]
278
304
pub fn try_with < F , R > ( & ' static self , f : F ) -> Result < R , AccessError >
@@ -452,7 +478,7 @@ impl<T: 'static> LocalKey<RefCell<T>> {
452
478
/// Panics if the key currently has its destructor running,
453
479
/// and it **may** panic if the destructor has previously been run for this thread.
454
480
///
455
- /// # Example
481
+ /// # Examples
456
482
///
457
483
/// ```
458
484
/// use std::cell::RefCell;
@@ -483,7 +509,7 @@ impl<T: 'static> LocalKey<RefCell<T>> {
483
509
/// Panics if the key currently has its destructor running,
484
510
/// and it **may** panic if the destructor has previously been run for this thread.
485
511
///
486
- /// # Example
512
+ /// # Examples
487
513
///
488
514
/// ```
489
515
/// use std::cell::RefCell;
0 commit comments