Skip to main content

IdFactory

Struct IdFactory 

Source
pub struct IdFactory<T>
where T: DenseId,
{ /* private fields */ }
Expand description

Sequential id allocator.

Implementations§

Source§

impl<T> IdFactory<T>
where T: DenseId,

Source

pub fn new() -> IdFactory<T>

Source

pub fn try_alloc(&mut self) -> Option<T>

Allocate the next id: Some(id) with id.id_nat() == count while the range lasts, None once count == id_bound (and usize can hold the increment — the id bound is at most usize::MAX + 1, so next saturating there means the range is done).

Source

pub fn alloc(&mut self) -> T

Allocate, panicking on exhaustion (production message parity).

Source

pub fn count(&self) -> usize

Trait Implementations§

Source§

impl<T> Default for IdFactory<T>
where T: DenseId,

Default (plain Rust; production parity).

Source§

fn default() -> IdFactory<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for IdFactory<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for IdFactory<T>

§

impl<T> Send for IdFactory<T>
where PhantomData<T>: Send,

§

impl<T> Sync for IdFactory<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for IdFactory<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for IdFactory<T>

§

impl<T> UnwindSafe for IdFactory<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.