iter_ref 0.2.0

Traits for iterating over referenced data without consuming the iterator
Documentation
//! Traits for iterating over referenced data without consuming the iterator.
//! 
//! I was tired of the iter() function not being a trait. So I made it one!
//! 
//! 

pub mod prelude;

/// Trait for iterating over references without consuming the iterator.
pub trait IterRef: IntoIterator {
    
    type IntoIterRef<'a>: Iterator<Item = &'a Self::Item> where Self: 'a;
    /// Iterates over the items as immutable references.
    /// 
    /// A 'reference' is a type that points to a different spot in memory where the actual data is.
    /// Being 'immutable' means that the reference can't change the underlying data.
    /// If you want to change the underlying data then use iter_mut()
    fn iter<'a>(&'a self) -> Self::IntoIterRef<'a>;
}
pub trait IterRefMut: IntoIterator {
    
    type IntoIterRefMut<'a>: Iterator<Item = &'a mut Self::Item> where Self: 'a;
    /// Iterates over the items as mutable references.
    /// 
    /// A 'reference' is a type that points to a different spot in memory where the actual data is.
    /// Being 'mutable' means that the reference can change the underlying data.
    /// 
    /// If you don't need to change the underlying data then prefer using 'iter()'
    fn iter_mut<'a>(&'a mut self) -> Self::IntoIterRefMut<'a>;
}

impl<T: IntoIterator> IterRef for T
where for<'a> &'a T: IntoIterator<Item = &'a T::Item>
{
    type IntoIterRef<'a> = <&'a Self as IntoIterator>::IntoIter where T: 'a;

    fn iter<'a>(&'a self) -> <&'a Self as IntoIterator>::IntoIter {
        self.into_iter()
    }
}

impl<T: IntoIterator> IterRefMut for T
where
for<'a> &'a Self: IntoIterator<Item = &'a<Self as IntoIterator>::Item>,
for<'a> &'a mut Self: IntoIterator<Item = &'a mut <Self as IntoIterator>::Item>,
{
    type IntoIterRefMut<'a> = <&'a mut Self as IntoIterator>::IntoIter where T: 'a;

    fn iter_mut<'a>(&'a mut self) -> <&'a mut Self as IntoIterator>::IntoIter {
        self.into_iter()
    }
}