We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option<_>
This issue proposes to add a variation of try_match! that evaluates to Option instead of Result.
try_match!
Option
Result
bind_match::bind_match!
extract::extract!
variant::get_variant!
matches2::option_match!
Result::ok
self
Ok(x)
Some(x)
try_match_ok!($expr, $pat)
match_ok!($expr, $pat)
match
get_match!($expr, $pat)
Iterator::filter_map
let array = [Var1(42), Var2, Var1(10)]; let filtered: Vec<_> = array .iter() .filter_map(|x| try_match_ok!(x, &Var1(_0) if _0 > 20)) .collect(); assert_eq!(filtered, [42]);
Combined with #3:
let array = [Var1(42), Var2, Var1(10)]; let filtered: Vec<_> = array .iter() .filter_map(try_match_ok!(, &Var1(_0) if _0 > 20)) .collect(); assert_eq!(filtered, [42]);
impl<T> Enum<T> { fn var1(&self) -> Option<&T> { try_match_ok!(self, Var1(_0)) } fn is_var2(&self) -> bool { matches!(self, Var2) } }
The text was updated successfully, but these errors were encountered:
Unstably added in commit f3137df
Sorry, something went wrong.
Change of plan: Insta-stabilized the feature in commit 293993e.
No branches or pull requests
This issue proposes to add a variation of
try_match!
that evaluates toOption
instead ofResult
.Prior Arts
bind_match::bind_match!
from bind_matchextract::extract!
from extract_macrovariant::get_variant!
from extract-variantmatches2::option_match!
from matches2Result::ok
matchesself
againstOk(x)
and returnsSome(x)
.Issues
try_match_ok!($expr, $pat)
(try_match!
+Result::ok
)match_ok!($expr, $pat)
(match
+Result::ok
)get_match!($expr, $pat)
Examples
Iterator::filter_map
Combined with #3:
Extracting Variants
The text was updated successfully, but these errors were encountered: