Simple request, feel free to dunk on me if this is an unreasonable or inappropriate request. In addition, if there is some syntax already like this, then excuse my ignorance and I would appreciate being pointed to it.
I have been working on a project that extensively uses the return type of Result<MyEnum, MyError>
, but this can be extended to other nested enums like Option<MyEnum>
Similar to how if let
allows the user to explore the conditional of a single branch of the "parent" enum (e.g. if let Ok(value) = result { .. }
, it would be nice to reduce the syntax overhead when attempting the following:
// result: Result<MyEnum, MyError>
if let Ok(value: MyEnum) = result {
match value {
MyEnum::Variant1 => (),
MyEnum::Variant2 => (),
}
}
or
// result: Result<MyEnum, MyError>
match if let Ok(value: MyEnum) = result { result } else { continue }
MyEnum::Variant1 => (),
MyEnum::Variant2 => (),
}
and reduce it to something along the lines of:
// result: Result<MyEnum, MyError>
match let Ok(value: MyEnum) = result {
MyEnum::Variant1 => (),
MyEnum::Variant2 => (),
}
with the assumption that the Err
case will skip the statement all-together, but the option to handle it
the window of context for let Ok(value) = result
will, as a result, stay consistent between the if
implementation as well as this proposed match
one
I have used match match
in the past for something similar. I am very ignorant on the development lift which is required for something like this, nor if people are privy to it, but it's something I am personally dealing with