pub trait BackingMap<K, V>: Sized {
// Required methods
fn new() -> Self;
fn insert(&mut self, key: K, value: V) -> Option<V>;
fn get(&self, key: &K) -> Option<&V>;
fn get_mut(&mut self, key: &K) -> Option<&mut V>;
fn remove(&mut self, key: &K) -> Option<V>;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
// Provided method
fn with_capacity(capacity: usize) -> Self { ... }
}Expand description
Trait for types that can back a structible struct.
This trait defines the operations required for a map type to be used
as the backing storage for a structible struct. It is implemented for
HashMap and BTreeMap from the standard library.
Users can implement this trait for custom map types to use them as backing storage.
Required Methods§
Sourcefn insert(&mut self, key: K, value: V) -> Option<V>
fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the map, returning the previous value if present.
Sourcefn get_mut(&mut self, key: &K) -> Option<&mut V>
fn get_mut(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value for the given key.
Provided Methods§
Sourcefn with_capacity(capacity: usize) -> Self
fn with_capacity(capacity: usize) -> Self
Creates a new, empty map with capacity for at least capacity elements.
Map types that don’t support pre-allocation (like BTreeMap) can ignore
the capacity hint and just call new().
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.