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

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

A weak version of Rc.

Weak pointers do not count towards determining if the inner value should be dropped.

The typical way to obtain a Weak pointer is to call Rc::downgrade.

See the module-level documentation for more details.

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 upgrade on the return value always gives None.

Examples

use std::rc::Weak;

let empty: Weak<i64> = Weak::new();
assert!(empty.upgrade().is_none());

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

Upgrades the Weak pointer to an Rc, if possible.

Returns None if the strong count has reached zero and the inner value 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();
assert!(strong_five.is_some());

// Destroy all strong pointers.
drop(strong_five);
drop(five);

assert!(weak_five.upgrade().is_none());

Trait Implementations

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

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

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

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

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

Examples

use std::rc::Weak;

let empty: Weak<i64> = Default::default();
assert!(empty.upgrade().is_none());

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

Makes a clone of the Weak pointer.

This creates another pointer to the same inner value, increasing the weak reference count.

Examples

use std::rc::Rc;

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

weak_five.clone();

Performs copy-assignment from source. Read more

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

Drops the Weak pointer.

This will decrement the weak reference count.

Examples

use std::rc::Rc;

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        println!("dropped!");
    }
}

let foo = Rc::new(Foo);
let weak_foo = Rc::downgrade(&foo);
let other_weak_foo = weak_foo.clone();

drop(weak_foo);   // Doesn't print anything
drop(foo);        // Prints "dropped!"

assert!(other_weak_foo.upgrade().is_none());

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

Formats the value using the given formatter.

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