Struct polymap::polymap::PolyMap [] [src]

pub struct PolyMap<K: Eq + Hash, S = RandomState> { /* fields omitted */ }

A key-value map that can contain varying types of values.

A single PolyMap instance can map a given key to varying types of values. Successive operations on this key must use the correct type or the operation will panic.

If you would like to store only one value of each type, use TypeMap.

Example

use polymap::PolyMap;

let mut map = PolyMap::new();

// Maps `&str` to `&str`.
map.insert("foo", "Hello, world!");

// Maps `&str` to `i32`.
map.insert("bar", 123);

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

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

Methods

impl<K: Eq + Hash> PolyMap<K, RandomState>
[src]

Constructs a new PolyMap.

Constructs a new PolyMap with space reserved for n elements.

impl<K: Eq + Hash, S: BuildHasher> PolyMap<K, S>
[src]

Creates an empty PolyMap 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 corresponding to the given key. Does not make any assertions about the type of the value.

Returns whether the map contains a value corresponding to the given key whose type is the same as the given type.

Example

use polymap::PolyMap;

let mut map = PolyMap::new();

map.insert("foo", 1);
assert_eq!(false, map.contains_key_of::<_, &str>("foo"));
assert_eq!(true, map.contains_key_of::<_, i32>("foo"));

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

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

Whether the entry is occupied or vacant, the type of value that can be inserted into the returned entry is constrained to T.

Panics

If the entry exists, but the type of value differs from the one requested.

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

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

Panics

If the key exists, but the type of value differs from the one requested.

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

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

Panics

If the key exists, but the type of value differs from the one requested.

Inserts a key-value pair into the map. If the key is already present, that value is returned. Otherwise, None is returned.

Panics

If the key exists, but has a value of a different type than the one given.

Returns an iterator visiting all keys in arbitrary order. Iterator element type is &K.

Returns the number of elements in the map.

Returns whether the map is empty.

Reserves capacity for at least additional additional elements.

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

Panics

If the key exists, but the type of value differs from the one requested.

Shrinks the capacity of the map as much as possible.

Trait Implementations

impl<K: Eq + Hash + Debug, S: BuildHasher> Debug for PolyMap<K, S>
[src]

Formats the value using the given formatter.

impl<K: Eq + Hash, S: BuildHasher + Default> Default for PolyMap<K, S>
[src]

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