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.
Trait Implementations§
source§impl Clone for CloneCounter
impl Clone for CloneCounter
source§impl Debug for CloneCounter
impl Debug for CloneCounter
source§impl Default for CloneCounter
impl Default for CloneCounter
source§impl Drop for CloneCounter
impl Drop for CloneCounter
source§impl From<CloneCounter> for CloneCounterObserver
impl From<CloneCounter> for CloneCounterObserver
source§fn from(value: CloneCounter) -> Self
fn from(value: CloneCounter) -> Self
source§impl From<CloneCounterObserver> for CloneCounter
impl From<CloneCounterObserver> for CloneCounter
source§fn from(value: CloneCounterObserver) -> Self
fn from(value: CloneCounterObserver) -> Self
source§impl Future for &CloneCounter
impl Future for &CloneCounter
source§impl IntoFuture for CloneCounter
impl IntoFuture for CloneCounter
§type IntoFuture = CloneCounterFuture
type IntoFuture = CloneCounterFuture
source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Auto Trait Implementations§
impl Freeze for CloneCounter
impl RefUnwindSafe for CloneCounter
impl Send for CloneCounter
impl Sync for CloneCounter
impl Unpin for CloneCounter
impl UnwindSafe for CloneCounter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)