File tree 1 file changed +20
-0
lines changed
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> {
353
353
/// to upgrade the weak reference before this function returns will result
354
354
/// in a `None` value. However, the weak reference may be cloned freely and
355
355
/// 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
+ /// ```
356
376
#[ unstable( feature = "arc_new_cyclic" , issue = "75861" ) ]
357
377
pub fn new_cyclic ( data_fn : impl FnOnce ( & Weak < T > ) -> T ) -> Rc < T > {
358
378
// Construct the inner in the "uninitialized" state with a single
You can’t perform that action at this time.
0 commit comments