Rust's impl Trait
syntax allows for concise and flexible code, especially when returning iterators or other complex types. By using impl Trait
, you can abstract away concrete types while ensuring optimal performance through Rust's zero-cost abstractions.
In this challenge, you will implement a function that filters strings from a slice, returning only those that start with a given keyword. The function will return an iterator over the filtered results. This approach demonstrates how to combine Rust's iterator combinators with the impl Trait
syntax.
Write a function named filter_starts_with
that:
String
&str
keyword.iter()
to iterate over references to the strings in the slice.filter
method takes a closure to apply a filtering condition.starts_with
method to check if a string starts with a keyword.move
in the closure to capture the keyword.