fn main() {
let mut example = vec!["hello", "james", "london", "vertuoso", "logarithms", "lovable"];
println!("{:#}", filter!(&mut example, "lo", "nd", "mes"))
}
#[macro_use]
#[macro_export]
macro_rules! filter {
($stories: expr, $($field: expr),+) => {
$stories.iter().filter(|x| {
$(
x.contains($field)
)+
}).collect()
}
}
This is a slightly simpler example of the macro I'm trying to create which will take in an arbitrary number of field
s and filter the list based on whether it contains any of the field
s.
In the above example, I would want to return ["hello", "london", "james"]
. Is this possible? I tried calling filter()
on each field
and adding ||
to x.contains...
but both do not compile.