Crates.io | enum_for_matches |
lib.rs | enum_for_matches |
version | 0.1.1 |
source | src |
created_at | 2020-09-10 10:20:56.651927 |
updated_at | 2020-09-10 10:27:50.2936 |
description | `enum_for_matches` is a procedural macro that runs a match arm for each enum variant passed into it regardless of type. |
homepage | |
repository | |
max_upload_size | |
id | 286974 |
size | 15,589 |
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:
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:
match e
{
TestEnum::I64(i) => { s = i.to_string(); }
TestEnum :: U64(i) => { s = i.to_string(); }
_ => { }
}
And print 80
.
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.