Skip to main content

AnyMultiMap

Struct AnyMultiMap 

Source
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

Source

pub fn new() -> AnyMultiMap

Creates a new empty AnyMultiMap.

Source

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.

Source

pub fn len<T: Any + Send + Sync>(&self) -> usize

Returns the number of values of type T stored in the AnyMultiMap.

Source

pub fn len_total(&self) -> usize

Returns the total number of values stored in the AnyMultiMap, across all types.

Source

pub fn contains<T: Any + Send + Sync>(&self) -> bool

Returns true if there are values of type T stored in the AnyMultiMap.

Source

pub fn contains_any(&self) -> bool

Returns true if there are any values stored in the AnyMultiMap, across all types.

Source

pub fn is_empty<T: Any + Send + Sync>(&self) -> bool

Returns true if there are no values of type T stored in the AnyMultiMap.

Source

pub fn is_completely_empty(&self) -> bool

Returns true if there are no values stored in the AnyMultiMap, across all types.

Source

pub fn clear<T: Any + Send + Sync>(&mut self)

Removes all values of type T from the AnyMultiMap.

Source

pub fn clear_all(&mut self)

Removes all values from the AnyMultiMap, across all types.

Source

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.

Source

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.

Source

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.

Source

pub fn insert_boxed(&mut self, value: AnyCloneBox)

Inserts a boxed value of any type into the AnyMultiMap.

Trait Implementations§

Source§

impl Debug for AnyMultiMap

Source§

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

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

impl Default for AnyMultiMap

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