pub trait MapStorage: Default {
// Required methods
fn get(&self, key: &usize) -> Option<&Entry>;
fn get_mut(&mut self, key: &usize) -> Option<&mut Entry>;
fn insert(&mut self, key: usize, entry: Entry) -> Option<Entry>;
fn remove(&mut self, key: &usize) -> Option<Entry>;
fn contains_key(&self, key: &usize) -> bool;
fn for_each_entry<F: FnMut(&Entry)>(&self, f: F);
fn clear(&mut self);
// Provided methods
fn reserve(&mut self, _additional: usize) { ... }
fn decrement_and_maybe_remove(
&mut self,
key: &usize,
) -> Option<(bool, usize)> { ... }
}Expand description
Trait abstracting over map implementations for arena storage.
This allows Arena to be generic over the underlying map type,
supporting both BTreeMap and HashMap.
Required Methods§
Sourcefn insert(&mut self, key: usize, entry: Entry) -> Option<Entry>
fn insert(&mut self, key: usize, entry: Entry) -> Option<Entry>
Insert an entry, returning the old value if present.
Sourcefn contains_key(&self, key: &usize) -> bool
fn contains_key(&self, key: &usize) -> bool
Check if a key exists.
Sourcefn for_each_entry<F: FnMut(&Entry)>(&self, f: F)
fn for_each_entry<F: FnMut(&Entry)>(&self, f: F)
Iterate over all entries.
Provided Methods§
Sourcefn reserve(&mut self, _additional: usize)
fn reserve(&mut self, _additional: usize)
Reserve capacity for additional entries.
This is a no-op for ordered maps (BTreeMap) but can improve performance for hash maps by avoiding rehashing during bulk inserts.
Sourcefn decrement_and_maybe_remove(&mut self, key: &usize) -> Option<(bool, usize)>
fn decrement_and_maybe_remove(&mut self, key: &usize) -> Option<(bool, usize)>
Decrement the count for a key and remove if zero.
Returns Some(true) if entry was found and removed,
Some(false) if entry was found but count > 0 after decrement,
None if entry was not found.
This uses entry API when available for single-lookup performance.
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.