We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3014e79 commit d9a16b4Copy full SHA for d9a16b4
1 file changed
library/std/src/thread/local.rs
@@ -469,6 +469,28 @@ impl<T: 'static> LocalKey<Cell<T>> {
469
pub fn replace(&'static self, value: T) -> T {
470
self.with(|cell| cell.replace(value))
471
}
472
+
473
+ /// Updates the contained value using a function.
474
+ ///
475
+ /// # Examples
476
477
+ /// ```
478
+ /// use std::cell::Cell;
479
480
+ /// thread_local! {
481
+ /// static X: Cell<i32> = const { Cell::new(5) };
482
+ /// }
483
484
+ /// X.update(|x| x + 1);
485
+ /// assert_eq!(X.get(), 6);
486
487
+ #[unstable(feature = "local_key_cell_update", issue = "143989")]
488
+ pub fn update(&'static self, f: impl FnOnce(T) -> T)
489
+ where
490
+ T: Copy,
491
+ {
492
+ self.with(|cell| cell.update(f))
493
+ }
494
495
496
impl<T: 'static> LocalKey<RefCell<T>> {
0 commit comments