I figured I can do "instanceof"-like filtering of enum types in an Iter with .filter(| x | match x { MyEnum::Type1(...) => true, _ => false). I was wondering if there is perhaps a more succinct way of doing this, perhaps without an inline match block. I guess I could implement a "filter_out" macro that expands into a respective match block, but I would prefer using no inline match block at all, if that's possible.
.filter(|x| matches!(x, MyEnum::Type1 { .. }))
// or if you don't want { .. }
.filter(|x| matches!(x, MyEnum::Type1(_, _)))
// or write a `is_type_1` method and
.filter(MyEnum::is_type_1);
Yes. One of the niceties of Rust is that your can use functions/methods directly like this when the arguments line up, so you don't have to write out a closure that just forwards the arguments.