File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,26 @@ impl<T> Rc<T> {
353353/// to upgrade the weak reference before this function returns will result 
354354/// in a `None` value. However, the weak reference may be cloned freely and 
355355/// stored for use at a later time. 
356+ /// 
357+ /// # Examples 
358+ /// 
359+ /// ``` 
360+ /// #![feature(arc_new_cyclic)] 
361+ /// #![allow(dead_code)] 
362+ /// use std::rc::{Rc, Weak}; 
363+ /// 
364+ /// struct Gadget { 
365+ ///     self_weak: Weak<Self>, 
366+ ///     // ... more fields 
367+ /// } 
368+ /// impl Gadget { 
369+ ///     pub fn new() -> Rc<Self> { 
370+ ///         Rc::new_cyclic(|self_weak| { 
371+ ///             Gadget { self_weak: self_weak.clone(), /* ... */ } 
372+ ///         }) 
373+ ///     } 
374+ /// } 
375+ /// ``` 
356376#[ unstable( feature = "arc_new_cyclic" ,  issue = "75861" ) ]  
357377    pub  fn  new_cyclic ( data_fn :  impl  FnOnce ( & Weak < T > )  -> T )  -> Rc < T >  { 
358378        // Construct the inner in the "uninitialized" state with a single 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments