pub struct Map<K, V>where
K: Key<K, V>,{ /* private fields */ }
Expand description
A map with a fixed, pre-determined size.
Implementations
sourceimpl<K, V> Map<K, V>where
K: Key<K, V>,
impl<K, V> Map<K, V>where
K: Key<K, V>,
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);
pub fn new() -> Map<K, V>
sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
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);
sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
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"));
sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
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"));
sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
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);
Auto Trait Implementations
impl<K, V> RefUnwindSafe for Map<K, V>where
<K as Key<K, V>>::Storage: RefUnwindSafe,
impl<K, V> Send for Map<K, V>where
<K as Key<K, V>>::Storage: Send,
impl<K, V> Sync for Map<K, V>where
<K as Key<K, V>>::Storage: Sync,
impl<K, V> Unpin for Map<K, V>where
<K as Key<K, V>>::Storage: Unpin,
impl<K, V> UnwindSafe for Map<K, V>where
<K as Key<K, V>>::Storage: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more