Skip to main content

IdAllocator

Struct IdAllocator 

Source
pub struct IdAllocator { /* private fields */ }
Expand description

A simple monotonic ID allocator for InteractionId.

This is intentionally tiny and deterministic. It is designed for applications that want “stable enough” IDs within a running process without introducing a full retained-mode UI tree.

Typical usage:

  • store one allocator in app state
  • allocate IDs for interactive widgets at creation time
  • reuse those IDs across frames when registering areas into InteractionCache

Notes:

  • IDs start at 1 by default (leaving 0 as a convenient “none”/sentinel if you want it).
  • Allocation is monotonic and does not reuse IDs.
  • If you need stable IDs across restarts, use your own hashing/registry instead.

Implementations§

Source§

impl IdAllocator

Source

pub const fn new() -> Self

Create a new allocator starting at 1.

Source

pub const fn with_start(start: InteractionId) -> Self

Create a new allocator starting at a custom value.

This can be useful if you want to reserve ranges (e.g. 1..1000 for built-ins, etc.).

Source

pub fn alloc(&mut self) -> InteractionId

Allocate the next unique InteractionId.

Panics on overflow (extremely unlikely in practice for TUIs).

Source

pub fn peek(&self) -> InteractionId

Returns the next ID that would be allocated (without allocating it).

Source

pub fn reset(&mut self, start: InteractionId)

Reset the allocator to a specific starting value.

This does not guarantee uniqueness relative to IDs previously allocated. It is intended for tests or tightly controlled scenarios.

Trait Implementations§

Source§

impl Clone for IdAllocator

Source§

fn clone(&self) -> IdAllocator

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IdAllocator

Source§

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

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

impl Default for IdAllocator

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.