pub trait SecondaryMap<K, V> {
type Iter<'a>: Iterator<Item = (K, &'a V)> + 'a
where Self: 'a,
K: 'a,
V: 'a;
// Required methods
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
fn default_value(&self) -> V;
fn ensure_capacity(&mut self, capacity: usize);
fn capacity(&self) -> usize;
fn get(&self, key: K) -> &V;
fn set(&mut self, key: K, val: V);
fn take(&mut self, key: K) -> V;
fn iter<'a>(&'a self) -> Self::Iter<'a>
where K: 'a,
V: 'a;
// Provided methods
fn remove(&mut self, key: K) { ... }
fn rekey(&mut self, old: K, new: Option<K>) { ... }
fn swap(&mut self, key0: K, key1: K)
where K: Clone,
V: Clone { ... }
}Expand description
A map from keys to values with default elements.
Querying a key that has not been set returns a default value.
Required Associated Types§
Required Methods§
Sourcefn with_capacity(capacity: usize) -> Self
fn with_capacity(capacity: usize) -> Self
Creates a new secondary map with specified capacity.
Sourcefn default_value(&self) -> V
fn default_value(&self) -> V
Returns the default value for the secondary map. Any key that has not been set will return this value.
Sourcefn ensure_capacity(&mut self, capacity: usize)
fn ensure_capacity(&mut self, capacity: usize)
Increases the capacity of the secondary map to capacity.
Sourcefn capacity(&self) -> usize
fn capacity(&self) -> usize
Returns the maximum index the secondary map can contain without allocating.
Provided Methods§
Sourcefn rekey(&mut self, old: K, new: Option<K>)
fn rekey(&mut self, old: K, new: Option<K>)
Remove key old and optionally move to key new.
This method is useful for rekey callbacks such as in
PortMut::set_num_ports and PortMut::compact_nodes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.