BackingContainer

Trait BackingContainer 

Source
pub trait BackingContainer<K, V>: Default {
    type Iter<'a>: Iterator<Item = (K, &'a V)>
       where V: 'a,
             Self: 'a;

    // Required methods
    fn insert(&mut self, k: K, v: V);
    fn get(&self, k: &K) -> Option<&V>;
    fn get_mut(&mut self, k: &K) -> Option<&mut V>;
    fn remove(&mut self, k: &K);
    fn iter(&self) -> Self::Iter<'_>;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Trait for containers that can be wrapped using GroupingContainer.

Required Associated Types§

Source

type Iter<'a>: Iterator<Item = (K, &'a V)> where V: 'a, Self: 'a

Type of iterator returned by the BackingContainer::iter method.

Required Methods§

Source

fn insert(&mut self, k: K, v: V)

Set the value at the provided key.

Source

fn get(&self, k: &K) -> Option<&V>

Get a reference to the value at the provided key, or None if the value doesn’t exist.

Source

fn get_mut(&mut self, k: &K) -> Option<&mut V>

Get mutable a reference to the value at the provided key, or None if the value doesn’t exist.

Source

fn remove(&mut self, k: &K)

Remove a value with the provided key, if it exists.

Source

fn iter(&self) -> Self::Iter<'_>

Iterate over all (key, value) tuples in the container.

Source

fn len(&self) -> usize

Return the number of elements in the container.

Provided Methods§

Source

fn is_empty(&self) -> bool

Return whether the container is empty.

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.

Implementations on Foreign Types§

Source§

impl<K: Eq + Hash + Clone, V> BackingContainer<K, V> for HashMap<K, V>

Source§

type Iter<'a> = Map<Iter<'a, K, V>, fn((&'a K, &'a V)) -> (K, &'a V)> where K: 'a, V: 'a

Source§

fn insert(&mut self, k: K, v: V)

Source§

fn get(&self, k: &K) -> Option<&V>

Source§

fn get_mut(&mut self, k: &K) -> Option<&mut V>

Source§

fn remove(&mut self, k: &K)

Source§

fn iter(&self) -> Self::Iter<'_>

Source§

fn len(&self) -> usize

Source§

impl<V> BackingContainer<usize, V> for Vec<Option<V>>

Source§

type Iter<'a> = FilterMap<Enumerate<Iter<'a, Option<V>>>, fn((usize, &'a Option<V>)) -> Option<(usize, &'a V)>> where V: 'a

Source§

fn insert(&mut self, k: usize, v: V)

Source§

fn get(&self, k: &usize) -> Option<&V>

Source§

fn get_mut(&mut self, k: &usize) -> Option<&mut V>

Source§

fn remove(&mut self, k: &usize)

Source§

fn iter(&self) -> Self::Iter<'_>

Source§

fn len(&self) -> usize

Implementors§