iter-trait 0.3.1

Iter trait for collectons.
Documentation
//! Map iterator traits.

use base::{HasData, Iter, IterMut};
use refs::{Ref, RefMut};

/// A trait for iterable collections which are a mapping of one type to another.
pub trait HasMapData: HasData {
    /// The type of the keys.
    type Key;

    /// The type of the values.
    type Value;
}

/// A trait for map-like collections which can be iterated by references to keys and values.
pub trait MapIter<'a>: HasMapData + Iter<'a> {
    /// Type of the references to the keys in the collection.
    ///
    /// For more information, see the `KeyRef` trait.
    type KeyRef: Ref<'a, Self::Key>;

    /// Type of the references to the values in the collection.
    ///
    /// For more information, see the `ValueRef` trait.
    type ValueRef: Ref<'a, Self::Value>;

    /// Type of the iterator over references to keys.
    type IterKeysRef: Iterator<Item = Self::KeyRef>;

    /// Type of the iterator over references to values.
    type IterValuesRef: Iterator<Item = Self::ValueRef>;

    /// Constructs an iterator over references to the keys in this collection.
    fn keys(&'a self) -> Self::IterKeysRef;

    /// Constructs an iterator over references to the values in this collection.
    fn values(&'a self) -> Self::IterValuesRef;
}

/// A trait for map-like collections which can be iterated by references to keys, and mutable
/// references to values.
pub trait MapIterMut<'a>: MapIter<'a> + IterMut<'a> {
    /// Type of the mutable references to the values in the collection.
    ///
    /// For more information, see the `ValueRefMut` trait.
    type ValueMut: RefMut<'a, Self::Value>;

    /// Type of the iterator over mutable references to values.
    type IterValuesMut: Iterator<Item = Self::ValueMut>;

    /// Constructs an iterator over mutable references to the values in this collection.
    fn values_mut(&'a mut self) -> Self::IterValuesMut;
}