pub struct Extensions { /* private fields */ }Expand description
Type-safe extensions container.
Stores typed values keyed by TypeId for O(1) retrieval without
runtime type checking after initial insertion.
Implementations§
Source§impl Extensions
impl Extensions
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create with pre-allocated capacity.
Sourcepub fn insert<T: Send + Sync + 'static>(&mut self, value: T)
pub fn insert<T: Send + Sync + 'static>(&mut self, value: T)
Insert a typed value into the extensions.
If a value of this type already exists, it is replaced.
§Example
use armature_core::Extensions;
let mut ext = Extensions::new();
ext.insert(42i32);
ext.insert("hello");Sourcepub fn insert_arc<T: Send + Sync + 'static>(&mut self, value: Arc<T>)
pub fn insert_arc<T: Send + Sync + 'static>(&mut self, value: Arc<T>)
Insert an Arc-wrapped value directly.
This is more efficient when you already have an Arc.
Sourcepub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
Get a reference to a typed value.
Returns None if no value of this type exists.
§Performance
This is O(1) and only involves a HashMap lookup followed by a pointer cast (no runtime type checking).
§Example
use armature_core::Extensions;
let mut ext = Extensions::new();
ext.insert(42i32);
assert_eq!(ext.get::<i32>(), Some(&42));
assert_eq!(ext.get::<String>(), None);Sourcepub fn get_arc<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
pub fn get_arc<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
Get an Arc reference to a typed value.
This is useful when you need to clone the Arc for async operations.
Sourcepub fn remove<T: Send + Sync + 'static>(&mut self) -> bool
pub fn remove<T: Send + Sync + 'static>(&mut self) -> bool
Remove a typed value from the extensions.
Returns true if the value existed and was removed.
Sourcepub fn extend(&mut self, other: Extensions)
pub fn extend(&mut self, other: Extensions)
Merge another extensions container into this one.
Values from other will overwrite values in self for the same type.
Trait Implementations§
Source§impl Clone for Extensions
impl Clone for Extensions
Source§fn clone(&self) -> Extensions
fn clone(&self) -> Extensions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more