Struct trillium_server_common::CloneCounter
source · pub struct CloneCounter(/* private fields */);
Expand description
an atomic counter that increments on clone & decrements on drop
One-indexed, because the first CloneCounter is included. If you don’t
want the original to count, construct a CloneCounterObserver
instead and use CloneCounterObserver::counter
to increment.
Awaiting a CloneCounter
will be pending until it is the only remaining
counter and resolve to ()
when the count is 1.
Implementations§
source§impl CloneCounter
impl CloneCounter
sourcepub fn current(&self) -> usize
pub fn current(&self) -> usize
Returns the current count. The first CloneCounter is one, so this can either be considered a one-indexed count of the total number of CloneCounters in memory
sourcepub fn decrement(&self)
pub fn decrement(&self)
Manually decrement the count. This is useful when taking a clone of the counter that does not represent an increase in the underlying property or resource being counted. This is called automatically on drop and is usually unnecessary to call directly
sourcepub fn increment(&self)
pub fn increment(&self)
Manually increment the count. unless paired with a decrement, this will prevent the clone counter from ever reaching zero. This is called automatically on clone.
sourcepub fn observer(&self) -> CloneCounterObserver
pub fn observer(&self) -> CloneCounterObserver
Returns an observer that can be cloned any number of times
without modifying the clone counter. See
CloneCounterObserver
for more.