iter-trait 0.1.0

Iterator trait for collectons.
Documentation
macro_rules! do_impl {
    (HasData for $impl_for:ty, $item:ty; $($gen:tt)*) => {
        impl<$($gen)*> $crate::base::HasData for $impl_for {
            type Item = $item;
        }
    };
    (
        MapIter for $name:ident, $impl_for:ty,
        ($key_item:ty, $keys_iter:ty),
        ($value_item:ty, $values_iter:ty); $($gen:tt)*
    ) => {
        impl<'a, $($gen)*> $crate::base::MapIter<'a> for $impl_for {
            type KeyRef = $key_item;
            type ValueRef = $value_item;
            type IterKeysRef = $keys_iter;
            type IterValuesRef = $values_iter;
            fn keys(&'a self) -> $keys_iter {
                $name::keys(self)
            }
            fn values(&'a self) -> $values_iter {
                $name::values(self)
            }
        }
    };
    (
        MapIterMut for $name:ident, $impl_for:ty,
        ($key_item:ty, $keys_iter:ty),
        ($value_item:ty, $values_iter:ty),
        ($value_item_mut:ty, $values_mut_iter:ty); $($gen:tt)*
    ) => {
        do_impl!(MapIter for $name, $impl_for,
                 ($key_item, $keys_iter),
                 ($value_item, $values_iter); $($gen)*);
        impl<'a, $($gen)*> $crate::base::MapIterMut<'a> for $impl_for {
            type ValueMut = $value_item_mut;
            type IterValuesMut = $values_mut_iter;

            fn values_mut(&'a mut self) -> $values_mut_iter {
                $name::values_mut(self)
            }
        }
    };
}

mod core {
    do_impl!(HasData for [T], T; T);
}


#[cfg(feature = "std")]
mod std {
    use std::collections::{HashMap, hash_map};
    use std::hash::Hash;

    do_impl!(MapIterMut for HashMap, HashMap<K, V>, 
             (&'a K, hash_map::Keys<'a, K, V>),
             (&'a V, hash_map::Values<'a, K, V>),
             (&'a mut V, hash_map::ValuesMut<'a, K, V>); K: 'a + Hash + Eq, V: 'a);
}

#[cfg(feature = "collections")]
mod collections {
    cfg_if! {
        if #[cfg(feature = "std")] {
            use std::collections::{BTreeMap, btree_map};
        } else {
            use collections::{BTreeMap, btree_map};
        }
    }

    do_impl!(MapIterMut for BTreeMap, BTreeMap<K, V>,
             (&'a K, btree_map::Keys<'a, K, V>),
             (&'a V, btree_map::Values<'a, K, V>),
             (&'a mut V, btree_map::ValuesMut<'a, K, V>); K: 'a + Ord, V: 'a);
}

#[cfg(feature = "linked-hash-map")]
mod linked_hash_map {
    use std::hash::Hash;
    use linked_hash_map::{self, LinkedHashMap};
    do_impl!(MapIter for LinkedHashMap, LinkedHashMap<K, V>,
             (&'a K, linked_hash_map::Keys<'a, K, V>),
             (&'a V, linked_hash_map::Values<'a, K, V>); K: 'a + Hash + Eq, V: 'a);
}

#[cfg(feature = "vec_map")]
mod vec_map {
    use vec_map::{self, VecMap};
    do_impl!(MapIter for VecMap, VecMap<T>,
             (usize, vec_map::Keys<'a, T>),
             (&'a T, vec_map::Values<'a, T>); T: 'a);
}