You mean like ‘matches!’?
let MyEnum(foo, bar, baz) = input but otherwise { do some stuff return some value }
Point being I don’t have to check for MyEnum-ness twice (like with matches! + if let) and the indented code is for the exception (no match) not the norm.
Tho I … guess !matches(MyEnum{ .. }) is not the worst… but it’s annoying to have this pattern all over my code instead of as some encoded concept we all use
let Some(y) = x else { do_stuff(); return };
I think it was a fairly recent addition to Rust.Here the type being matched is:
enum Option<T> {
None,
Some(T)
}
let x = Some(42);
let Some(y) = x else { panic!("None") };