Registry

Struct Registry 

Source
pub struct Registry<T> { /* private fields */ }
Expand description

A strict, capacity-limited registry that separates Cold Path (registration) from Hot Path (access) to ensure consistent performance.

Implementations§

Source§

impl<T> Registry<T>

Source

pub fn new(capacity: usize) -> Result<Self, RegistryError>

Creates a new registry with a fixed capacity. Pre-allocates all necessary memory to avoid runtime allocations.

Source

pub fn register( &mut self, name: impl Into<String>, item: T, ) -> Result<HandlerId<T>, RegistryError>

[Cold Path] Registers an item with a string ID. Fails if capacity is exceeded or name already exists.

Source

pub fn get(&self, id: HandlerId<T>) -> Option<&T>

[Hot Path] Access item by ID (No allocation, O(1))

Source

pub fn get_mut(&mut self, id: HandlerId<T>) -> Option<&mut T>

[Hot Path] Mutable access item by ID (No allocation, O(1))

Source

pub fn lookup(&self, name: &str) -> Option<HandlerId<T>>

[Cold Path] Look up a handler ID by name

Source

pub fn remove(&mut self, id: HandlerId<T>) -> Option<T>

[Cold Path] Remove an item by ID. Updates generation to invalidate old handles and cleans up name map.

Source

pub fn capacity(&self) -> usize

Returns the fixed capacity of the registry.

Source

pub fn count(&self) -> usize

Returns the current number of items.

Source

pub fn keys(&self) -> impl Iterator<Item = &String>

Returns an iterator over all registered names.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &T)>

Returns an iterator over all registered items with their names.

Auto Trait Implementations§

§

impl<T> Freeze for Registry<T>

§

impl<T> RefUnwindSafe for Registry<T>
where T: RefUnwindSafe,

§

impl<T> Send for Registry<T>
where T: Send,

§

impl<T> Sync for Registry<T>
where T: Sync,

§

impl<T> Unpin for Registry<T>
where T: Unpin,

§

impl<T> UnwindSafe for Registry<T>
where T: UnwindSafe,

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 = 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 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.