iter_trait/
map.rs

1//! Map iterator traits.
2
3use base::{HasData, Iter, IterMut};
4use refs::{Ref, RefMut};
5
6/// A trait for iterable collections which are a mapping of one type to another.
7pub trait HasMapData: HasData {
8    /// The type of the keys.
9    type Key;
10
11    /// The type of the values.
12    type Value;
13}
14
15/// A trait for map-like collections which can be iterated by references to keys and values.
16pub trait MapIter<'a>: HasMapData + Iter<'a> {
17    /// Type of the references to the keys in the collection.
18    ///
19    /// For more information, see the `KeyRef` trait.
20    type KeyRef: Ref<'a, Self::Key>;
21
22    /// Type of the references to the values in the collection.
23    ///
24    /// For more information, see the `ValueRef` trait.
25    type ValueRef: Ref<'a, Self::Value>;
26
27    /// Type of the iterator over references to keys.
28    type IterKeysRef: Iterator<Item = Self::KeyRef>;
29
30    /// Type of the iterator over references to values.
31    type IterValuesRef: Iterator<Item = Self::ValueRef>;
32
33    /// Constructs an iterator over references to the keys in this collection.
34    fn keys(&'a self) -> Self::IterKeysRef;
35
36    /// Constructs an iterator over references to the values in this collection.
37    fn values(&'a self) -> Self::IterValuesRef;
38}
39
40/// A trait for map-like collections which can be iterated by references to keys, and mutable
41/// references to values.
42pub trait MapIterMut<'a>: MapIter<'a> + IterMut<'a> {
43    /// Type of the mutable references to the values in the collection.
44    ///
45    /// For more information, see the `ValueRefMut` trait.
46    type ValueMut: RefMut<'a, Self::Value>;
47
48    /// Type of the iterator over mutable references to values.
49    type IterValuesMut: Iterator<Item = Self::ValueMut>;
50
51    /// Constructs an iterator over mutable references to the values in this collection.
52    fn values_mut(&'a mut self) -> Self::IterValuesMut;
53}