pub unsafe trait Counter: Sized {
// Required methods
fn new() -> Self;
fn strong_count(&self) -> usize;
fn weak_count(&self) -> usize;
fn inc_strong_for_new_ref(&self);
fn dec_strong_for_drop(&self) -> bool;
fn inc_weak_for_new_ref(&self);
fn dec_weak_for_drop(&self) -> bool;
fn try_inc_strong_for_upgrade(&self) -> bool;
}
Expand description
Trait for structs that can count references
wiwi
includes two implementations: one for single threaded access (akin
to std
’s Rc
), and the other for atomic multithreaded access (akin to
std
’s Arc
).
§Safety
You must implement this trait correctly (ie. functions must return correct values), as values returned from functions are directly used to control the allocation/deallocation of memory and dropping of values.
Required Methods§
Sourcefn strong_count(&self) -> usize
fn strong_count(&self) -> usize
Get the strong reference count
Sourcefn weak_count(&self) -> usize
fn weak_count(&self) -> usize
Get the weak reference count
Don’t subtract the “fake” weak reference that is held by all the strong references.
Sourcefn inc_strong_for_new_ref(&self)
fn inc_strong_for_new_ref(&self)
Increment the strong count for creation of a new strong reference
Sourcefn dec_strong_for_drop(&self) -> bool
fn dec_strong_for_drop(&self) -> bool
Decrements the strong count for dropping a reference, returning true
if there are no more strong pointers left (and the value and items in
the slice should be dropped)
Sourcefn inc_weak_for_new_ref(&self)
fn inc_weak_for_new_ref(&self)
Increments the weak count for creation of a new weak reference
Sourcefn dec_weak_for_drop(&self) -> bool
fn dec_weak_for_drop(&self) -> bool
Decrements the weak count for dropping a reference, returning true
if there are no more weak pointers left (and the allocation should be
deallocated)
Sourcefn try_inc_strong_for_upgrade(&self) -> bool
fn try_inc_strong_for_upgrade(&self) -> bool
Increment the strong count if it is possible to upgrade a weak pointer
to strong, and return true
, otherwise return false
and do nothing
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.