Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huitseeker/match-opt
Convenience macro injecting a partial pattern match into an Option
https://github.com/huitseeker/match-opt
macro option rust
Last synced: 5 days ago
JSON representation
Convenience macro injecting a partial pattern match into an Option
- Host: GitHub
- URL: https://github.com/huitseeker/match-opt
- Owner: huitseeker
- License: mit
- Created: 2022-02-05T17:07:47.000Z (almost 3 years ago)
- Default Branch: trunk
- Last Pushed: 2022-09-19T17:40:01.000Z (over 2 years ago)
- Last Synced: 2024-12-24T05:54:06.024Z (14 days ago)
- Topics: macro, option, rust
- Language: Shell
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## match_opt ![Build Status](https://github.com/huitseeker/match-opt/workflows/Rust/badge.svg)
**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:
```rust
let some_results = vec!["1", "2", "3", "foo", "bar", "4"].map(|v| v.parse::());
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.
Documentation
-------------The API can be found [here](https://docs.rs/match-opt/).
Installation
------------Add the following line to the dependencies of your `Cargo.toml`:
```toml
match_opt = "0.1.0"
```Contributors
------------The authors of this code is François Garillot ([@huitseeker](https://github.com/huitseeker)).
License
-------This project is [MIT licensed](./LICENSE).