https://github.com/ctrlcctrlv/enum_for_matches
`enum_for_matches` runs a match arm for each enum variant passed into it regardless of type. It's a Rust procedural macro.
https://github.com/ctrlcctrlv/enum_for_matches
Last synced: 11 months ago
JSON representation
`enum_for_matches` runs a match arm for each enum variant passed into it regardless of type. It's a Rust procedural macro.
- Host: GitHub
- URL: https://github.com/ctrlcctrlv/enum_for_matches
- Owner: ctrlcctrlv
- License: other
- Created: 2020-09-10T10:17:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-20T18:11:14.000Z (over 5 years ago)
- Last Synced: 2025-02-18T06:13:45.676Z (over 1 year ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `enum_for_matches`
`enum_for_matches` runs a match arm for each enum variant passed into it
regardless of type. So, you can make a string out of an enum which wraps
numeric types individually, such as `serde_value::Value` for example. See
README.md on GitHub for more information.
For example, this:
```rust
enum TestEnum {
I64(i64),
U64(u64)
}
let e = TestEnum::I64(80);
let mut s = String::new();
enum_for_matches::run!(e, {TestEnum::I64(i) | TestEnum::U64(i)}, {s = i.to_string();});
eprintln!("{}", &s);
```
Would expand to:
```rust
match e
{
TestEnum::I64(i) => { s = i.to_string(); }
TestEnum::U64(i) => { s = i.to_string(); }
_ => { }
}
```
And print `80`.
## Contributing
This crate is considered feature complete. It uses a copious amount of
`.clone()`'s, many of which are probably removable. However, since this only
runs at compile time, on probably quite small vectors, I couldn't be bothered.