pub struct AnyMultiMap { /* private fields */ }Expand description
A type-erased multimap storing multiple values per type.
AnyMultiMap allows storing multiple values of the same type, with each
type identified by its TypeId. Values are stored in vectors behind
trait objects, enabling type-erased access while maintaining type safety.
§Examples
use any_container::AnyMultiMap;
let mut multimap = AnyMultiMap::new();
multimap.insert(1i32);
multimap.insert(2i32);
multimap.insert("hello".to_string());
assert_eq!(multimap.len::<i32>(), 2);
assert_eq!(multimap.get::<i32>(), &[1, 2]);
assert_eq!(multimap.len::<String>(), 1);
assert_eq!(multimap.get::<String>(), &["hello".to_string()]);Implementations§
Source§impl AnyMultiMap
impl AnyMultiMap
Sourcepub fn new() -> AnyMultiMap
pub fn new() -> AnyMultiMap
Creates a new empty AnyMultiMap.
Sourcepub fn type_count(&self) -> usize
pub fn type_count(&self) -> usize
Returns the number of different types stored in the AnyMultiMap.
This counts unique types, not the total number of values.
Sourcepub fn len<T: Any + Send + Sync>(&self) -> usize
pub fn len<T: Any + Send + Sync>(&self) -> usize
Returns the number of values of type T stored in the AnyMultiMap.
Sourcepub fn len_total(&self) -> usize
pub fn len_total(&self) -> usize
Returns the total number of values stored in the AnyMultiMap, across all types.
Sourcepub fn contains<T: Any + Send + Sync>(&self) -> bool
pub fn contains<T: Any + Send + Sync>(&self) -> bool
Returns true if there are values of type T stored in the AnyMultiMap.
Sourcepub fn contains_any(&self) -> bool
pub fn contains_any(&self) -> bool
Returns true if there are any values stored in the AnyMultiMap, across all types.
Sourcepub fn is_empty<T: Any + Send + Sync>(&self) -> bool
pub fn is_empty<T: Any + Send + Sync>(&self) -> bool
Returns true if there are no values of type T stored in the AnyMultiMap.
Sourcepub fn is_completely_empty(&self) -> bool
pub fn is_completely_empty(&self) -> bool
Returns true if there are no values stored in the AnyMultiMap, across all types.
Sourcepub fn clear<T: Any + Send + Sync>(&mut self)
pub fn clear<T: Any + Send + Sync>(&mut self)
Removes all values of type T from the AnyMultiMap.
Sourcepub fn get<T: Any + Send + Sync>(&self) -> &[T]
pub fn get<T: Any + Send + Sync>(&self) -> &[T]
Returns a slice of all values of type T stored in the AnyMultiMap.
If no values of type T exist, an empty slice is returned.
Sourcepub fn get_mut<T: Any + Send + Sync>(&mut self) -> AnyVecMutRef<'_, T>
pub fn get_mut<T: Any + Send + Sync>(&mut self) -> AnyVecMutRef<'_, T>
Returns a mutable reference to the vector values of type T stored in the AnyMultiMap.
If no values of type T exist, a new vector is created and returned.
This method is useful for adding multiple values of the same type efficiently.
Sourcepub fn insert<T: Any + Send + Sync>(&mut self, value: T)
pub fn insert<T: Any + Send + Sync>(&mut self, value: T)
Inserts a value of type T into the AnyMultiMap.
§Note
This is a convenience method that calls get_mut and pushes the value into the vector.
If you need to insert multiple values of the same type, consider using get_mut directly
to avoid repeated lookups.
Sourcepub fn insert_boxed(&mut self, value: AnyCloneBox)
pub fn insert_boxed(&mut self, value: AnyCloneBox)
Inserts a boxed value of any type into the AnyMultiMap.