| Crates.io | match_opt |
| lib.rs | match_opt |
| version | 0.1.3 |
| created_at | 2022-02-05 17:12:38.164801+00 |
| updated_at | 2025-08-01 20:55:30.209139+00 |
| description | A macro for turning a partial match into a full match returning an option. |
| homepage | |
| repository | https://github.com/huitseeker/match-opt |
| max_upload_size | |
| id | 527507 |
| size | 11,747 |
match_opt is a macro that converts a partial pattern-match into one that returns an Option.
This can be used as a shorthand to simplify a complex pattern-match, for which only one or few cases are useful.
For example:
let some_results = vec!["1", "2", "3", "foo", "bar", "4"].map(|v| v.parse::<usize>());
let some_pattern_match = some_results.filter_map{|x| match x {
Ok(v) if v > 2 => Some(v),
_ => None,
}};
// this is equivalent to
let alternate_pattern_match = some_results.filter_map{|x| match_opt!(x, OK(v) if v > 2 => v)};
This crate has no dependencies.
The API can be found here.
Add the following line to the dependencies of your Cargo.toml:
match_opt = "0.1.0"
The authors of this code is François Garillot (@huitseeker).
This project is MIT licensed.