[][src]Struct typemap::TypeMap

pub struct TypeMap<A: ?Sized = dyn UnsafeAny> where
    A: UnsafeAnyExt
{ /* fields omitted */ }

A map keyed by types.

Can contain one value of any type for each key type, as defined by the Assoc trait.

You usually do not need to worry about the A type parameter, but it can be used to add bounds to the possible value types that can be stored in this map. Usually, you are looking for ShareMap, which is Send + Sync.

Methods

impl TypeMap[src]

pub fn new() -> TypeMap[src]

Create a new, empty TypeMap.

impl<A: UnsafeAnyExt + ?Sized> TypeMap<A>[src]

pub fn custom() -> TypeMap<A>[src]

Create a new, empty TypeMap.

Can be used with any A parameter; new is specialized to get around the required type annotations when using this function.

pub fn insert<K: Key>(&mut self, val: K::Value) -> Option<K::Value> where
    K::Value: Any + Implements<A>, 
[src]

Insert a value into the map with a specified key type.

pub fn get<K: Key>(&self) -> Option<&K::Value> where
    K::Value: Any + Implements<A>, 
[src]

Find a value in the map and get a reference to it.

pub fn get_mut<K: Key>(&mut self) -> Option<&mut K::Value> where
    K::Value: Any + Implements<A>, 
[src]

Find a value in the map and get a mutable reference to it.

pub fn contains<K: Key>(&self) -> bool[src]

Check if a key has an associated value stored in the map.

pub fn remove<K: Key>(&mut self) -> Option<K::Value> where
    K::Value: Any + Implements<A>, 
[src]

Remove a value from the map.

Returns true if a value was removed.

pub fn entry<'a, K: Key>(&'a mut self) -> Entry<'a, K, A> where
    K::Value: Any + Implements<A>, 
[src]

Get the given key's corresponding entry in the map for in-place manipulation.

pub unsafe fn data(&self) -> &HashMap<TypeId, Box<A>>[src]

Read the underlying HashMap

pub unsafe fn data_mut(&mut self) -> &mut HashMap<TypeId, Box<A>>[src]

Get a mutable reference to the underlying HashMap

pub fn len(&self) -> usize[src]

Get the number of values stored in the map.

pub fn is_empty(&self) -> bool[src]

Return true if the map contains no values.

pub fn clear(&mut self)[src]

Remove all entries from the map.

Trait Implementations

impl<A: Default + ?Sized> Default for TypeMap<A> where
    A: UnsafeAnyExt
[src]

impl<A: ?Sized> Clone for TypeMap<A> where
    A: UnsafeAnyExt,
    Box<A>: Clone
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<A: Debug + ?Sized> Debug for TypeMap<A> where
    A: UnsafeAnyExt
[src]

Auto Trait Implementations

impl<A: ?Sized> Send for TypeMap<A> where
    A: Send

impl<A: ?Sized> Sync for TypeMap<A> where
    A: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> UnsafeAny for T where
    T: Any
[src]