| Crates.io | tagname |
| lib.rs | tagname |
| version | 0.3.1 |
| created_at | 2022-10-20 17:56:56.845621+00 |
| updated_at | 2022-12-22 14:55:14.566504+00 |
| description | get the name of a variant in your enum as a string |
| homepage | https://github.com/khrynczenko/tagname |
| repository | https://github.com/khrynczenko/tagname |
| max_upload_size | |
| id | 692766 |
| size | 14,190 |
This library exports a trait called TagName that exposes a
tag_name method which is used for retrieving a name (tag) of a currently hold variant within an enum value.
More importantly, together with TagName trait comes a derive(TagName)
macro that can automatically implement the trait.
use tagname::TagName;
#[derive(TagName)]
enum MyTaggedUnion {
#[tag(case = "lower")]
Yes,
#[tag(case = "upper")]
No,
Maybe(usize),
}
#[test]
fn return_correct_tag_names() {
let v1 = MyTaggedUnion::Yes;
let v2 = MyTaggedUnion::No;
let v3 = MyTaggedUnion::Maybe(1);
assert_eq!(v1.tag_name(), "yes");
assert_eq!(v2.tag_name(), "NO");
assert_eq!(v3.tag_name(), "Maybe");
}