How to return an Iterator with associated type being generic from a function?

For a function like this:

fn generate_even(a: i32, b: i32) -> impl Iterator<Item = i32> {
    (a..b).filter(|x| x % 2 == 0)
}

I want to make it generic, instead of the concrete type i32 I want to have any type that is range-able and provide a filter implementation.

Tried the formula below without success:

fn generate_even(a: T, b: T) -> impl Iterator<Item = T>
    where T: // range + filter + what to put here?
{
    (a..b).filter(|x| x % 2 == 0)
}

How can something like this be implemented?



from Recent Questions - Stack Overflow https://ift.tt/3lojc89
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations