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>
impl<T: ?Sized> Wobbly<T>
sourcepub fn weak_count(&self) -> usize
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.
sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Gets the number of strong pointers pointing to this allocation.
Note that one group of Wobbly
s 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>
impl<T: ?Sized> Clone for Wobbly<T>
source§fn clone(&self) -> Self
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 Wobbly
s 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)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: ?Sized> Drop for Wobbly<T>
impl<T: ?Sized> Drop for Wobbly<T>
source§fn drop(&mut self)
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.