File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -469,6 +469,29 @@ 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+ /// #![feature(local_key_cell_update)] 
479+ /// use std::cell::Cell; 
480+ /// 
481+ /// thread_local! { 
482+ ///     static X: Cell<i32> = const { Cell::new(5) }; 
483+ /// } 
484+ /// 
485+ /// X.update(|x| x + 1); 
486+ /// assert_eq!(X.get(), 6); 
487+ /// ``` 
488+ #[ unstable( feature = "local_key_cell_update" ,  issue = "143989" ) ]  
489+     pub  fn  update ( & ' static  self ,  f :  impl  FnOnce ( T )  -> T ) 
490+     where 
491+         T :  Copy , 
492+     { 
493+         self . with ( |cell| cell. update ( f) ) 
494+     } 
472495} 
473496
474497impl < T :  ' static >  LocalKey < RefCell < T > >  { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments