Trait Map

Source
pub trait Map<T>: Default {
    type Key: Copy + Eq + Debug + 'static;
    type Iter<'a>: Iterator<Item = (Self::Key, &'a T)>
       where Self: 'a,
             T: 'a;
    type IterMut<'a>: Iterator<Item = (Self::Key, &'a mut T)>
       where Self: 'a,
             T: 'a;

    // Required methods
    fn len(&self) -> usize;
    fn get(&self, index: Self::Key) -> Option<&T>;
    fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>;
    fn remove(&mut self, index: Self::Key) -> Option<T>;
    fn clear(&mut self);
    fn iter(&self) -> Self::Iter<'_>;
    fn iter_mut(&mut self) -> Self::IterMut<'_>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn contains_key(&self, index: Self::Key) -> bool { ... }
}
Expand description

A trait for a generic map that can be used as a node or an edge map in a Graph.

Required Associated Types§

Source

type Key: Copy + Eq + Debug + 'static

The type of key used by the map.

Source

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

The type for an immutable iterator over the nodes in the map.

Source

type IterMut<'a>: Iterator<Item = (Self::Key, &'a mut T)> where Self: 'a, T: 'a

The type for a mutable iterator over the nodes in the map.

Required Methods§

Source

fn len(&self) -> usize

Returns the amount of nodes in the map.

Source

fn get(&self, index: Self::Key) -> Option<&T>

Returns an immutable reference to a value by its key or None in case the key is not present in the map.

Source

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Returns a mutable reference to a value by its key or None in case the key is not present in the map.

Source

fn remove(&mut self, index: Self::Key) -> Option<T>

Removes a value from a map by its key. Returns the removed value or None in case the key was not present in the map.

Source

fn clear(&mut self)

Removes all the nodes from the map.

Source

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

Returns an immutable iterator over the nodes in a map.

Source

fn iter_mut(&mut self) -> Self::IterMut<'_>

Returns a mutable iterator over the nodes in a map.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the map is empty.

Source

fn contains_key(&self, index: Self::Key) -> bool

Returns true if a map contains the specified key.

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, T, S> Map<T> for HashMap<K, T, S>
where K: Copy + Eq + Hash + Debug + 'static, S: BuildHasher + Default,

Available on crate features std or indexmap only.
Source§

type Key = K

Source§

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

Source§

type IterMut<'a> = Map<IterMut<'a, K, T>, fn((&'a K, &'a mut T)) -> (K, &'a mut T)> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn contains_key(&self, index: Self::Key) -> bool

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Source§

impl<K, T, S> Map<T> for IndexMap<K, T, S>
where K: Copy + Eq + Hash + Debug + 'static, S: BuildHasher + Default,

Available on crate features std or indexmap only.
Source§

type Key = K

Source§

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

Source§

type IterMut<'a> = Map<IterMut<'a, K, T>, fn((&'a K, &'a mut T)) -> (K, &'a mut T)> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn contains_key(&self, index: Self::Key) -> bool

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Source§

impl<K: Copy + Eq + Ord + Debug + 'static, T> Map<T> for BTreeMap<K, T>

Available on crate feature alloc only.
Source§

type Key = K

Source§

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

Source§

type IterMut<'a> = Map<IterMut<'a, K, T>, fn((&'a K, &'a mut T)) -> (K, &'a mut T)> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn contains_key(&self, index: Self::Key) -> bool

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Source§

impl<K: Key + 'static, T> Map<T> for SlotMap<K, T>

Available on crate feature slotmap only.
Source§

type Key = K

Source§

type Iter<'a> = Iter<'a, K, T> where Self: 'a, T: 'a

Source§

type IterMut<'a> = IterMut<'a, K, T> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

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

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Source§

impl<K: Key + 'static, T> Map<T> for DenseSlotMap<K, T>

Available on crate feature slotmap only.
Source§

type Key = K

Source§

type Iter<'a> = Iter<'a, K, T> where Self: 'a, T: 'a

Source§

type IterMut<'a> = IterMut<'a, K, T> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

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

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Source§

impl<K: Key + 'static, T> Map<T> for HopSlotMap<K, T>

Available on crate feature slotmap only.
Source§

type Key = K

Source§

type Iter<'a> = Iter<'a, K, T> where Self: 'a, T: 'a

Source§

type IterMut<'a> = IterMut<'a, K, T> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

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

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Source§

impl<K: Key + 'static, T> Map<T> for SecondaryMap<K, T>

Available on crate feature slotmap only.
Source§

type Key = K

Source§

type Iter<'a> = Iter<'a, K, T> where Self: 'a, T: 'a

Source§

type IterMut<'a> = IterMut<'a, K, T> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn contains_key(&self, index: Self::Key) -> bool

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Source§

impl<K: Key + 'static, T> Map<T> for SparseSecondaryMap<K, T>

Available on crate feature slotmap only.
Source§

type Key = K

Source§

type Iter<'a> = Iter<'a, K, T> where Self: 'a, T: 'a

Source§

type IterMut<'a> = IterMut<'a, K, T> where Self: 'a, T: 'a

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn contains_key(&self, index: Self::Key) -> bool

Source§

fn get(&self, index: Self::Key) -> Option<&T>

Source§

fn get_mut(&mut self, index: Self::Key) -> Option<&mut T>

Source§

fn remove(&mut self, index: Self::Key) -> Option<T>

Source§

fn clear(&mut self)

Source§

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

Source§

fn iter_mut(&mut self) -> Self::IterMut<'_>

Implementors§