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§
source§impl 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§
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 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§
source§impl<F> FutureExt for Fwhere
F: Future + ?Sized,
impl<F> FutureExt for Fwhere F: Future + ?Sized,
source§fn race<F>(self, other: F) -> Race<Self, F>where
Self: Sized,
F: Future<Output = Self::Output>,
fn race<F>(self, other: F) -> Race<Self, F>where Self: Sized, F: Future<Output = Self::Output>,
source§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
source§impl<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?
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more