Struct fixed_map::Map

source ·
pub struct Map<K, V>where
    K: Key<K, V>,
{ /* private fields */ }
Expand description

A map with a fixed, pre-determined size.

Implementations

A map implementation that uses fixed storage.

Examples

use fixed_map::Map;

#[derive(fixed_map::Key)]
enum MyKey {
    Foo,
    Bar,
}

let mut m = Map::new();
m.insert(MyKey::Foo, 42);

assert_eq!(m.get(&MyKey::Foo), Some(&42));
assert_eq!(m.get(&MyKey::Bar), None);

Returns a reference to the value corresponding to the key.

Examples
use fixed_map::Map;

#[derive(fixed_map::Key)]
enum Key {
    One,
    Two,
}

let mut map = Map::new();
map.insert(Key::One, "a");
assert_eq!(map.get(&Key::One), Some(&"a"));
assert_eq!(map.get(&Key::Two), None);

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

Examples
use fixed_map::Map;

#[derive(fixed_map::Key)]
enum Key {
    One,
    Two,
}

let mut map = Map::new();
map.insert(Key::One, "a");
if let Some(x) = map.get_mut(&Key::One) {
    *x = "b";
}
assert_eq!(map.get(&Key::One), Some(&"b"));

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

Examples
use fixed_map::Map;

#[derive(fixed_map::Key)]
enum Key {
    One,
    Two,
}

let mut map = Map::new();
assert_eq!(map.insert(Key::One, "a"), None);
assert_eq!(map.is_empty(), false);

map.insert(Key::Two, "b");
assert_eq!(map.insert(Key::Two, "c"), Some("b"));
assert_eq!(map.get(&Key::Two), Some(&"c"));

Removes a key from the map, returning the value at the key if the key was previously in the map.

Examples
use fixed_map::Map;

#[derive(fixed_map::Key)]
enum Key {
    One,
    Two,
}

let mut map = Map::new();
map.insert(Key::One, "a");
assert_eq!(map.remove(&Key::One), Some("a"));
assert_eq!(map.remove(&Key::One), None);

Returns true if the map contains no elements.

Examples
use fixed_map::Map;

#[derive(fixed_map::Key)]
enum Key {
    One,
    Two,
}

let mut map = Map::new();
assert!(map.is_empty());
map.insert(Key::One, "a");
assert!(!map.is_empty());

Returns the number of elements in the map.

Examples
use fixed_map::Map;

#[derive(fixed_map::Key)]
enum Key {
    One,
    Two,
}

let mut map = Map::new();
assert_eq!(map.len(), 0);
map.insert(Key::One, "a");
assert_eq!(map.len(), 1);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.