Struct wobbly::sync::Wobbly

source ·
pub struct Wobbly<T: ?Sized> { /* private fields */ }
Expand description

A thread-safe atomically reference-counting pointer, similar to Weak, which provides wobbly-shared ownership of a value of type T, allocated on the heap.

See the module-level documentation for more details.

A Wobbly<T> pointer is Send and Sync iff T is Send and Sync, just like Weak:

fn check_send_sync<T: Send + Sync>() {}

check_send_sync::<Wobbly<()>>()
fn check_send_sync<T: Send + Sync>() {}

// `Cell<()>` cannot be shared between threads safely
check_send_sync::<Wobbly<std::cell::Cell<()>>>()
fn check_send_sync<T: Send + Sync>() {}

// `MutexGuard<()>` cannot be sent between threads safely
check_send_sync::<Wobbly<std::sync::MutexGuard<()>>>()

Implementations§

source§

impl<T: ?Sized> Wobbly<T>

source

pub fn new(strong: Arc<T>) -> Self

Creates a new Wobbly<T> from an owning (strong) Arc pointer.

Wobbly::new creates a new group of Wobbly pointers, which keeps the inner value alive as long as none of the Wobblys is dropped. To extend an existing group, clone one of its Wobbly pointers.

source

pub fn downgrade(&self) -> Weak<T>

Creates a new Weak pointer to this allocation.

source

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

Attempts to upgrade the Wobbly pointer to an Arc, delaying dropping of the inner value if successful.

Returns None if the inner value has since been dropped.

source

pub fn weak_count(&self) -> usize

Gets the number of weak pointers pointing to this allocation.

Note that this Wobbly counts as one weak pointer.

source

pub fn strong_count(&self) -> usize

Gets the number of strong pointers pointing to this allocation.

Note that one group of Wobblys that was created only by clone-ing counts as one strong pointer as long as none of the group members has been dropped.

Trait Implementations§

source§

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

source§

fn clone(&self) -> Self

Makes a clone of the Wobbly pointer that points to the same allocation.

Cloning a Wobbly pointer also extends its group of Wobblys that share the same one owning pointer. If this owning pointer has not yet been released, the newly cloned Wobbly will release it if it is the first Wobbly pointer of the group to be dropped.

1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

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

source§

fn drop(&mut self)

Drops the Wobbly pointer, which releases one non-owning (weak) pointer to the value. If this Wobbly is the first of its group, created only by clone-ing, that is dropped, an owning (strong) pointer is released as well, and the value may be dropped iff this was the last remaining owning (strong) pointer.

Auto Trait Implementations§

§

impl<T> Freeze for Wobbly<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for Wobbly<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for Wobbly<T>
where T: Sync + Send + ?Sized,

§

impl<T> Sync for Wobbly<T>
where T: Sync + Send + ?Sized,

§

impl<T> Unpin for Wobbly<T>
where T: ?Sized,

§

impl<T> UnwindSafe for Wobbly<T>
where T: RefUnwindSafe + ?Sized,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.