I am trying to learn more about Rust be reimplementing a toy version of some other code I have written:
I get this error:
54:38 error: cannot infer an appropriate lifetime due to conflicting requirements
around some code like:
pub struct Composed<F1, F2> { first: F1, second: Arc<F2> }
impl<X, F1, F2> FlatMapper<X> for Composed<F1, F2>
where F1: FlatMapper<X>,
F2: FlatMapper<<<F1 as FlatMapper<X>>::Output as Iterator>::Item> {
type Output = Box<Iterator<Item = <<F2 as FlatMapper<<<F1 as FlatMapper<X>>::Output as Iterator>::Item>>::Output as Iterator>::Item>>;
fn apply(&self, i: X) -> <Self as FlatMapper<X>>::Output {
let it1 = self.first.apply(i);
let sec = self.second.clone();
box it1.flat_map(|y| sec.apply(y))
}
}
I expected that sec would be dropped when the result of flat_map is dropped, and there would be no problem. But I guess that is not the case.
I'd love a clear explanation of why my expectation is incorrect and also any suggestions to change the design to have the same effect without hitting this issue.
Thanks in advance for any time spent helping me learn.