pub struct Counter<T: Countable>(/* private fields */);Expand description
An opaque counter that produces unique IDs of type T via Counter::get_and_increment.
This is separate from the ID types themselves so that holding an ID does not give the ability to mint new IDs.
Implementations§
Source§impl<T: Countable> Counter<T>
impl<T: Countable> Counter<T>
Sourcepub fn get_and_increment(&mut self) -> T
pub fn get_and_increment(&mut self) -> T
Gets the current counter value and increments for the next call.
Sourcepub fn range_up_to(&self) -> impl DoubleEndedIterator<Item = T> + FusedIterator
pub fn range_up_to(&self) -> impl DoubleEndedIterator<Item = T> + FusedIterator
Returns an iterator from zero up to (but excluding) the current counter value.
This is useful for iterating already-allocated values.
Trait Implementations§
impl<T: Copy + Countable> Copy for Counter<T>
impl<T: Eq + Countable> Eq for Counter<T>
Source§impl<T: Ord + Countable> Ord for Counter<T>
impl<T: Ord + Countable> Ord for Counter<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq + Countable> PartialEq for Counter<T>
impl<T: PartialEq + Countable> PartialEq for Counter<T>
Source§impl<T: PartialOrd + Countable> PartialOrd for Counter<T>
impl<T: PartialOrd + Countable> PartialOrd for Counter<T>
impl<T: PartialEq + Countable> StructuralPartialEq for Counter<T>
Auto Trait Implementations§
impl<T> Freeze for Counter<T>
impl<T> RefUnwindSafe for Counter<T>where
T: RefUnwindSafe,
impl<T> Send for Counter<T>where
T: Send,
impl<T> Sync for Counter<T>where
T: Sync,
impl<T> Unpin for Counter<T>where
T: Unpin,
impl<T> UnsafeUnpin for Counter<T>
impl<T> UnwindSafe for Counter<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.