Struct alloc::arc::Weak [] [src]

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

A weak pointer to an Arc.

Weak pointers will not keep the data inside of the Arc alive, and can be used to break cycles between Arc pointers.

Methods

impl<T: ?Sized> Weak<T>

fn upgrade(&self) -> Option<Arc<T>>

Upgrades a weak reference to a strong reference.

Upgrades the Weak<T> reference to an Arc<T>, if possible.

Returns None if there were no strong references and the data was destroyed.

Examples

use std::sync::Arc;

let five = Arc::new(5);

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

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

impl<T> Weak<T>

fn new() -> Weak<T>

Unstable (downgraded_weak #30425)

: recently added

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

#![feature(downgraded_weak)]

use std::sync::Weak;

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

Trait Implementations

impl<T: ?Sized + Sync + Send> Send for Weak<T>

impl<T: ?Sized + Sync + Send> Sync for Weak<T>

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

impl<T: ?Sized + Debug> Debug for Weak<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: ?Sized> Clone for Weak<T>

fn clone(&self) -> Weak<T>

Makes a clone of the Weak<T>.

This increases the weak reference count.

Examples

use std::sync::Arc;

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

weak_five.clone();

fn clone_from(&mut self, source: &Self)1.0.0

impl<T: ?Sized> Drop for Weak<T>

fn drop(&mut self)

Drops the Weak<T>.

This will decrement the weak reference count.

Examples

use std::sync::Arc;

{
    let five = Arc::new(5);
    let weak_five = Arc::downgrade(&five);

    // stuff

    drop(weak_five); // explicit drop
}
{
    let five = Arc::new(5);
    let weak_five = Arc::downgrade(&five);

    // stuff

} // implicit drop