[<<][rust][>>][..]
Thu Mar 5 01:02:56 EST 2015

boilerplate

Is there a way around this?  The type annotation is cumbersome and
repeated 3 times:
- struct def
- constructor
- trait implementation

struct FIR2<T,I> where I:Iterator<Item=T>, T:Clone { last: T, iter: I } 
fn fir2<T,I> (iter: I, init: T) -> FIR2<T,I> where I:Iterator<Item=T>, T:Clone { FIR2 { last: init, iter: iter } }
impl<T,I> Iterator for FIR2<T,I> where I:Iterator<Item=T>, T:Clone {
    type Item = (T,T);
    fn next(&mut self) -> Option<(T,T)> {
        match (self.iter.next()) {
            None => None,
            Some(current) => {
                let last = mem::replace(&mut self.last, current.clone()); 
                Some((current, last))
            }
        }
    }
}




[Reply][About]
[<<][rust][>>][..]