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 PolyMap 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 key-value pairs from the map.

Returns whether the map contains a value of the given type.

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

Returns a reference to the value of the given type.

If no value of the given type exists, None is returned.

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

If no value of the given type exists, None is returned.

Inserts a value into the map. If a value of the same 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.

Removes a value of the given type from the map, returning it. If no value of the type exists, None is returned.

Reserves capacity for at least additional additional elements.

Shrinks the capacity of the map as much as possible.

Trait Implementations

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

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