What's the right way to return a boxed clonable iterator from an expression? For example:
fn example() -> Box<Iterator<Item = String> + Clone> {
unimplemented!()
}
This gives me an error that only automatic traits can be specified in this manner:
error[E0225]: only auto traits can be used as additional traits in a trait object
--> src/main.rs:1:47
|
1 | fn example() -> Box<Iterator<Item = String> + Clone> {
| ^^^^^ non-auto additional trait
This is my real code:
let my_iterator = {
if a {
Box::new(/* ... */) as Box<Iterator<Item = String> + Clone>
} else {
Box::new(/* ... */) as Box<Iterator<Item = String> + Clone>
}
};
let pb = ProgressBar::new(my_iterator.clone().count() as u64);
If alternative suggestions are considered: the two branches represent one path for loading from a file, the other path for generating automatically, and I'd rather not keep things in memory if they aren't needed.