pub struct Weak<T: ?Sized> { /* private fields */ }
Available on crate features alloc or std only.
Expand description

A weakly reference counted pointer.

This is an equivalent to std::sync::Weak, but using portable-atomic for synchronization. See the documentation for the standard library’s Weak for more details.

Examples

use portable_atomic_util::Arc;
use std::thread;

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

thread::spawn(move || {
    let five = weak_five.upgrade().unwrap();
    assert_eq!(*five, 5);
});

Implementations§

Try to upgrade this Weak pointer to a strong pointer.

Example
use portable_atomic_util::Arc;

let five = Arc::new(5);

let weak = Arc::downgrade(&five);
assert!(weak.upgrade().is_some());

Get the number of strong pointers to this allocation.

Get the number of weak pointers to this allocation.

Create a new dangling Weak pointer.

Example
use portable_atomic_util::Weak;

let weak = Weak::<i32>::new();

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.