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
1by default (leaving0as 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
impl IdAllocator
Sourcepub const fn with_start(start: InteractionId) -> Self
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.).
Sourcepub fn alloc(&mut self) -> InteractionId
pub fn alloc(&mut self) -> InteractionId
Allocate the next unique InteractionId.
Panics on overflow (extremely unlikely in practice for TUIs).
Sourcepub fn peek(&self) -> InteractionId
pub fn peek(&self) -> InteractionId
Returns the next ID that would be allocated (without allocating it).
Sourcepub fn reset(&mut self, start: InteractionId)
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
impl Clone for IdAllocator
Source§fn clone(&self) -> IdAllocator
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for IdAllocator
impl Debug for IdAllocator
Auto Trait Implementations§
impl Freeze for IdAllocator
impl RefUnwindSafe for IdAllocator
impl Send for IdAllocator
impl Sync for IdAllocator
impl Unpin for IdAllocator
impl UnsafeUnpin for IdAllocator
impl UnwindSafe for IdAllocator
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