Struct alloc::rc::Weak1.4.0 [] [src]

pub struct Weak<T: ?Sized> { /* fields omitted */ }

A 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>
[src]

Constructs a new Weak<T> without an accompanying instance of T.

This allocates memory for T, but does not initialize it. Calling Weak::upgrade() on the return value always gives None.

Examples

use std::rc::Weak;

let empty: Weak<i64> = Weak::new();Run

impl<T: ?Sized> Weak<T>
[src]

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

use std::rc::Rc;

let five = Rc::new(5);

let weak_five = Rc::downgrade(&five);

let strong_five: Option<Rc<_>> = weak_five.upgrade();Run

Trait Implementations

impl<T: ?Sized> !Send for Weak<T>
[src]

impl<T: ?Sized> !Sync for Weak<T>
[src]

impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T>
[src]

impl<T: ?Sized> Drop for Weak<T>
[src]

Drops the Weak<T>.

This will decrement the weak reference count.

Examples

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 dropRun

impl<T: ?Sized> Clone for Weak<T>
[src]

Makes a clone of the Weak<T>.

This increases the weak reference count.

Examples

use std::rc::Rc;

let weak_five = Rc::downgrade(&Rc::new(5));

weak_five.clone();Run

Performs copy-assignment from source. Read more

impl<T: ?Sized + Debug> Debug for Weak<T>
[src]

Formats the value using the given formatter.

impl<T> Default for Weak<T>
1.10.0
[src]

Creates a new Weak<T>.