Struct trillium_server_common::CloneCounter
source · [−]pub struct CloneCounter(_);
Expand description
an atomic counter that increments on clone & decrements on drop
use futures_lite::future::poll_once;
let counter = CloneCounter::new();
assert_eq!(counter.current(), 0);
counter.await; // ready immediately
let counter = CloneCounter::new();
assert_eq!(counter.current(), 0);
let clone = counter.clone();
assert_eq!(counter.current(), 1);
let clone2 = counter.clone();
assert_eq!(counter.current(), 2);
assert_eq!(poll_once(clone2).await, None); // pending
assert_eq!(counter.current(), 1);
std::mem::drop(clone);
assert_eq!(counter.current(), 0);
counter.await; // ready
Implementations
sourceimpl CloneCounter
impl CloneCounter
sourcepub fn current(&self) -> usize
pub fn current(&self) -> usize
Returns the current count. The first CloneCounter is zero, so this can either be considered a zero-indexed count of the total number of CloneCounters in memory, or a one-indexed count of the number of non-original clones.
Trait Implementations
sourceimpl Clone for CloneCounter
impl Clone for CloneCounter
sourceimpl Debug for CloneCounter
impl Debug for CloneCounter
sourceimpl Default for CloneCounter
impl Default for CloneCounter
sourcefn default() -> CloneCounterⓘNotable traits for CloneCounterimpl Future for CloneCounter type Output = ();
fn default() -> CloneCounterⓘNotable traits for CloneCounterimpl Future for CloneCounter type Output = ();
Returns the “default value” for a type. Read more
sourceimpl Drop for CloneCounter
impl Drop for CloneCounter
sourceimpl Future for CloneCounter
impl Future for CloneCounter
Auto Trait Implementations
impl !RefUnwindSafe for CloneCounter
impl Send for CloneCounter
impl Sync for CloneCounter
impl Unpin for CloneCounter
impl !UnwindSafe for CloneCounter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<F> FutureExt for Fwhere
F: Future + ?Sized,
impl<F> FutureExt for Fwhere
F: Future + ?Sized,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Catches panics while polling the future. Read more
sourceimpl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
sourcefn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more