I am relying on iterators to perform some streaming processing. I have an issue where I have to store the result of a
filter_map in a struct. For this purpose, I have used generics. You can have a minimal example of my issue in this playground. It seems that it cannot conclude that the result of my
FilterMap struct) is a
u32 iterator, even though
.next() returns a
Option<u32> as expected from a
u32 iterator (
let test: Option<u32> = new_iter.next(); does not make any compilation error).
As a temporary fix, I have stored the Iterator as a
Box<Iterator<Item=u32>>, which works just fine. However, I am concerned about some sort of performance hit since I am relying on dynamic function dispatch on a pretty hot path.
Am I doing something wrong? What can I do to fix it? In my program, the iterator should stay in the struct but I am open to suggestions.