Skip to main content

MapStorage

Trait MapStorage 

Source
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§

Source

fn get(&self, key: &usize) -> Option<&Entry>

Get an entry by key.

Source

fn get_mut(&mut self, key: &usize) -> Option<&mut Entry>

Get a mutable entry by key.

Source

fn insert(&mut self, key: usize, entry: Entry) -> Option<Entry>

Insert an entry, returning the old value if present.

Source

fn remove(&mut self, key: &usize) -> Option<Entry>

Remove an entry by key.

Source

fn contains_key(&self, key: &usize) -> bool

Check if a key exists.

Source

fn for_each_entry<F: FnMut(&Entry)>(&self, f: F)

Iterate over all entries.

Source

fn clear(&mut self)

Clear all entries.

Provided Methods§

Source

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.

Source

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.

Implementors§