Struct std::rc::Weak
[−]
[src]
pub struct Weak<T> where T: ?Sized {
// some fields omitted
}
1.4.0A weak version of Rc<T>
.
Weak references do not count when determining if the inner value should be dropped.
See the module level documentation for more.
Methods
impl<T> Weak<T>
fn new() -> Weak<T>
Constructs a new Weak<T>
without an accompanying instance of T.
This allocates memory for T, but does not initialize it. Calling
Weak
Examples
#![feature(downgraded_weak)] fn main() { use std::rc::Weak; let empty: Weak<i64> = Weak::new(); }#![feature(downgraded_weak)] use std::rc::Weak; let empty: Weak<i64> = Weak::new();
impl<T> Weak<T> where T: ?Sized
fn upgrade(&self) -> Option<Rc<T>>
Upgrades a weak reference to a strong reference.
Upgrades the Weak<T>
reference to an Rc<T>
, if possible.
Returns None
if there were no strong references and the data was
destroyed.
Examples
fn main() { use std::rc::Rc; let five = Rc::new(5); let weak_five = Rc::downgrade(&five); let strong_five: Option<Rc<_>> = weak_five.upgrade(); }use std::rc::Rc; let five = Rc::new(5); let weak_five = Rc::downgrade(&five); let strong_five: Option<Rc<_>> = weak_five.upgrade();
Trait Implementations
impl<T> Debug for Weak<T> where T: Debug + ?Sized
impl<T> Clone for Weak<T> where T: ?Sized
fn clone(&self) -> Weak<T>
Makes a clone of the Weak<T>
.
This increases the weak reference count.
Examples
fn main() { use std::rc::Rc; let weak_five = Rc::downgrade(&Rc::new(5)); weak_five.clone(); }use std::rc::Rc; let weak_five = Rc::downgrade(&Rc::new(5)); weak_five.clone();
fn clone_from(&mut self, source: &Self)
1.0.0
impl<T> Drop for Weak<T> where T: ?Sized
fn drop(&mut self)
Drops the Weak<T>
.
This will decrement the weak reference count.
Examples
fn main() { use std::rc::Rc; { let five = Rc::new(5); let weak_five = Rc::downgrade(&five); // stuff drop(weak_five); // explicit drop } { let five = Rc::new(5); let weak_five = Rc::downgrade(&five); // stuff } // implicit drop }use std::rc::Rc; { let five = Rc::new(5); let weak_five = Rc::downgrade(&five); // stuff drop(weak_five); // explicit drop } { let five = Rc::new(5); let weak_five = Rc::downgrade(&five); // stuff } // implicit drop