pub struct UniqueIdAllocator<T: IntegerIdCounter> { /* private fields */ }Expand description
Allocates unique integer ids.
Guarantees that each call to the Self::alloc function will return a unique id,
unless Self::reset is called.
Ids start at IntegerIdCounter::START by default, counting upwards from there.
Implementations§
Source§impl<T: IntegerIdCounter> UniqueIdAllocator<T>
impl<T: IntegerIdCounter> UniqueIdAllocator<T>
Sourcepub fn max_used_id(&self) -> Option<T>
pub fn max_used_id(&self) -> Option<T>
Return the maximum currently used id,
or None if no ids have been allocated yet.
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new allocator,
using T::START as the first id (usually zero).
Sourcepub const fn with_start(start: T) -> Self
pub const fn with_start(start: T) -> Self
Create a new allocator, using the specified value as the first id.
Sourcepub fn alloc(&self) -> T
pub fn alloc(&self) -> T
Attempt to allocate a new id, panicking if none are available.
See Self::try_alloc for a version that returns an error
Sourcepub fn try_alloc(&self) -> Result<T, IdExhaustedError<T>>
pub fn try_alloc(&self) -> Result<T, IdExhaustedError<T>>
Attempt to allocate a new id, returning an error if there are no more available.
Trait Implementations§
Source§impl<T: Clone + IntegerIdCounter> Clone for UniqueIdAllocator<T>
impl<T: Clone + IntegerIdCounter> Clone for UniqueIdAllocator<T>
Source§fn clone(&self) -> UniqueIdAllocator<T>
fn clone(&self) -> UniqueIdAllocator<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug + IntegerIdCounter> Debug for UniqueIdAllocator<T>
impl<T: Debug + IntegerIdCounter> Debug for UniqueIdAllocator<T>
Source§impl<T: IntegerIdCounter> Default for UniqueIdAllocator<T>
impl<T: IntegerIdCounter> Default for UniqueIdAllocator<T>
Auto Trait Implementations§
impl<T> !Freeze for UniqueIdAllocator<T>
impl<T> !RefUnwindSafe for UniqueIdAllocator<T>
impl<T> Send for UniqueIdAllocator<T>where
T: Send,
impl<T> !Sync for UniqueIdAllocator<T>
impl<T> Unpin for UniqueIdAllocator<T>where
T: Unpin,
impl<T> UnwindSafe for UniqueIdAllocator<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