I'm using iproduct iterator which takes two iterators and return cross product. The second param must me clonable.
I'd like to sometimes pass an iterator as the second argument, and sometimes collect it for perfomance improvements. This is my code (playground):
use itertools::iproduct;
fn main() {
let left_part = (1..10).into_iter();
let it = (1..10).into_iter();
let collect = true;
let right_part = if collect { it.collect::<Vec<i32>>() } else { it };
let cross_product = iproduct!(left_part, right_part);
}
The problem is that if/else have incompatible types. If I put it inside a Box and say that both of them implement Clone trait it's throwing error. How could I solve it?
Thanks in advance