Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khrynczenko/tagname
derive macro that gives you a name of a current tag inside a variant as a string
https://github.com/khrynczenko/tagname
rust rust-crate rust-lang rust-language rust-library
Last synced: about 1 month ago
JSON representation
derive macro that gives you a name of a current tag inside a variant as a string
- Host: GitHub
- URL: https://github.com/khrynczenko/tagname
- Owner: khrynczenko
- License: mit
- Created: 2022-10-17T19:20:43.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-10T16:47:31.000Z (almost 2 years ago)
- Last Synced: 2024-03-15T06:46:26.996Z (8 months ago)
- Topics: rust, rust-crate, rust-lang, rust-language, rust-library
- Language: Rust
- Homepage:
- Size: 38.1 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
tagname
=============
[](https://github.com/khrynczenko/tagname)
[](https://crates.io/crates/tagname)
[](https://docs.rs/tagname)
[](https://github.com/khrynczenko/tagname/actions?query=branch%3Amaster)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.```rust
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");
}
```