I'm attemping to make a struct with a Filter
iterator inside:
struct Foo {
inner_iter: Filter<...>,
}
I'm then going to make Foo an Iterator itself, which will use the Filter internally.
The problem is, I can't seem to figure out what goes in between the braces after Filter
. The docs say Filter is the following:
pub struct Filter<'a, A, T> {
// some fields omitted
}
A
seems to be my return type. What are 'a
and T
? Nothing I attempt makes it compile.
Thanks!
You can see here that
Filter
implementsIterator
trait in the following way:This means that yes,
A
is its element type, andT
is underlying iterator type. If you look intoFilter
definition, you will also find that'a
is lifetime of environment of predicate closure.If you want to make your own wrapper for the
Filter
, it could look like this:You need to pass through all parameters to
Filter
. Of course, if you're working with some specific element type, you can specify it instead of using type parameter:However, you still need to pass
'a
andT
because they are likely to be arbitrary.