Struct std::sync::WeakUnstable
[-] [+]
[src]
pub struct Weak<T> { // some fields omitted }
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> Weak<T> where T: Send, T: Sync
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
fn main() { use std::sync::Arc; let five = Arc::new(5); let weak_five = five.downgrade(); let strong_five: Option<Arc<_>> = weak_five.upgrade(); }use std::sync::Arc; let five = Arc::new(5); let weak_five = five.downgrade(); let strong_five: Option<Arc<_>> = weak_five.upgrade();
Trait Implementations
impl<T> Send for Weak<T> where T: Send, T: Sync
impl<T> Sync for Weak<T> where T: Send, T: Sync
impl<T> Clone for Weak<T> where T: Send, T: Sync
fn clone(&self) -> Weak<T>
Makes a clone of the Weak<T>
.
This increases the weak reference count.
Examples
fn main() { use std::sync::Arc; let weak_five = Arc::new(5).downgrade(); weak_five.clone(); }use std::sync::Arc; let weak_five = Arc::new(5).downgrade(); weak_five.clone();
fn clone_from(&mut self, &Weak<T>)
impl<T> Drop for Weak<T> where T: Send, T: Sync
fn drop(&mut self)
Drops the Weak<T>
.
This will decrement the weak reference count.
Examples
fn main() { use std::sync::Arc; { let five = Arc::new(5); let weak_five = five.downgrade(); // stuff drop(weak_five); // explicit drop } { let five = Arc::new(5); let weak_five = five.downgrade(); // stuff } // implicit drop }use std::sync::Arc; { let five = Arc::new(5); let weak_five = five.downgrade(); // stuff drop(weak_five); // explicit drop } { let five = Arc::new(5); let weak_five = five.downgrade(); // stuff } // implicit drop