File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -469,6 +469,28 @@ impl<T: 'static> LocalKey<Cell<T>> {
469469    pub  fn  replace ( & ' static  self ,  value :  T )  -> T  { 
470470        self . with ( |cell| cell. replace ( value) ) 
471471    } 
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+     } 
472494} 
473495
474496impl < T :  ' static >  LocalKey < RefCell < T > >  { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments