I'm not sure how return a generic Map struct now that the declaration for Map has changed. The new declaration is:
pub struct Map<A, B, I: Iterator<A>, F: FnMut<(A,), B>> {
// some fields omitted
}
I'm not sure how to return one of these from a function:
fn something<A: Clone, I: Iterator<A>>(iter: I) -> Map<A, (A,A), I, **what goes here**> {
iter.map(|x| (x.clone(), x))
}
I've tried using the signature of the closure I'm using...
fn something<A: Clone, I: Iterator<A>>(iter: I) -> Map<A, (A,A), I, |A| -> (A,A)> {
iter.map(|x| (x.clone(), x))
}
But then rust complains that I need an explicit lifetime bound. I'm not sure why I need this, but I add it anyway:
fn something<'a, A: Clone, I: Iterator<A>>(iter: I) -> Map<A, (A,A), I, |A|:'a -> (A,A)> {
iter.map(|x| (x.clone(), x))
}
But then I get the error: the trait core::ops::Fn<(A,), (A, A)> is not implemented for the type 'a |A|:'a -> (A, A)
I haven't been able to progress any further, and at this point I'm just trying random things. Can someone help me understand how to use the new Map struct?
fn something<'a, A, I: Iterator<A>>(input: I) -> Map<'a, A, (A, A), I>worked fine - awelkie