pub struct IdentityManager {
    free: Vec<u32>,
    epochs: Vec<u32>,
}
Expand description

A simple structure to allocate Id identifiers.

Calling alloc returns a fresh, never-before-seen id. Calling free marks an id as dead; it will never be returned again by alloc.

Use IdentityManager::default to construct new instances.

IdentityManager returns Ids whose index values are suitable for use as indices into a Storage<T> that holds those ids’ referents:

  • Every live id has a distinct index value. Each live id’s index selects a distinct element in the vector.

  • IdentityManager prefers low index numbers. If you size your vector to accommodate the indices produced here, the vector’s length will reflect the highwater mark of actual occupancy.

  • IdentityManager reuses the index values of freed ids before returning ids with new index values. Freed vector entries get reused.

See the module-level documentation for an overview of how this fits together.

Fields§

§free: Vec<u32>

Available index values. If empty, then epochs.len() is the next index to allocate.

§epochs: Vec<u32>

The next or currently-live epoch value associated with each Id index.

If there is a live id with index i, then epochs[i] is its epoch; any id with the same index but an older epoch is dead.

If index i is currently unused, epochs[i] is the epoch to use in its next Id.

Implementations§

source§

impl IdentityManager

source

pub fn alloc<I: TypedId>(&mut self, backend: Backend) -> I

Allocate a fresh, never-before-seen id with the given backend.

The backend is incorporated into the id, so that ids allocated with different backend values are always distinct.

source

pub fn free<I: TypedId + Debug>(&mut self, id: I)

Free id. It will never be returned from alloc again.

Trait Implementations§

source§

impl Debug for IdentityManager

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for IdentityManager

source§

fn default() -> IdentityManager

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<T> WasmNotSend for Twhere T: Send,

source§

impl<T> WasmNotSync for Twhere T: Sync,