Struct polymap::typemap::TypeMap [] [src]

pub struct TypeMap<S = RandomState> { /* fields omitted */ }

A container for values of varying types.

Values contained in a TypeMap are stored uniquely according to their type. This means that, for each possible type, only one value may be stored in a single TypeMap instance.

If you would like to store multiple values of a given type, mapped to individual keys, use PolyMap.

Example

use polymap::TypeMap;

let mut map = TypeMap::new();

// Stores a `&str` value
map.insert("Hello, world!");

// Stores an `i32` value
map.insert(123);

// Gets a reference to the stored value
let &foo: &&str = map.get().unwrap();
assert_eq!(foo, "Hello, world!");

let &bar: &i32 = map.get().unwrap();
assert_eq!(bar, 123);

Methods

impl TypeMap<RandomState>
[src]

Constructs a new TypeMap.

Constructs a new TypeMap with space reserved for n elements.

impl<S: BuildHasher> TypeMap<S>
[src]

Creates an empty TypeMap which will use the given hash builder to hash keys.

Removes all values from the map.

Returns whether the map contains a value corresponding to the given type.

Returns the number of elements the map can hold without reallocating.

Returns the type's corresponding entry in the map for in-place manipulation.

Returns a reference to the value corresponding to the given type.

If the type is not contained within the map, None will be returned.

Returns a mutable reference to the value corresponding to the given type.

If the type is not contained within the map, None will be returned.

Inserts a value into the map. If a value of that type is already present, that value is returned. Otherwise, None is returned.

Returns the number of elements in the map.

Returns whether the map is empty.

Reserves capacity for at least additional additional elements.

Removes a value from the map, returning the value if one existed.

Shrinks the capacity of the map as much as possible.

Trait Implementations

impl<S> Debug for TypeMap<S>
[src]

Formats the value using the given formatter.

impl<S: BuildHasher + Default> Default for TypeMap<S>
[src]

Returns the "default value" for a type. Read more