#macro-derive #variant-name #enums #struct

derive-name

Derive macro to get the name of a struct, enum or enum variant

5 releases (2 stable)

1.1.0 Jul 28, 2023
1.0.0 Jul 27, 2023
0.1.2 Mar 27, 2023
0.1.1 Mar 27, 2023
0.1.0 Mar 27, 2023

#1342 in Rust patterns

Download history 26/week @ 2024-03-29 6/week @ 2024-04-05 5/week @ 2024-04-12 88/week @ 2024-04-19 124/week @ 2024-04-26 351/week @ 2024-05-03 18/week @ 2024-05-10 186/week @ 2024-05-17 31/week @ 2024-05-24 319/week @ 2024-05-31 305/week @ 2024-06-07 54/week @ 2024-06-14 3/week @ 2024-06-21

690 downloads per month

ISC license

6KB
67 lines

Derive Name

CI Crate Docs

Derive macro to get the name of a struct, enum or enum variant.

Name

use derive_name::Name;

#[derive(Name)]
struct Alice;

#[derive(Name)]
enum Bob {}

assert_eq!(Alice::name(), "Alice");
assert_eq!(Bob::name(), "Bob");

Named

use derive_name::Named;

#[derive(derive_name::Name)]
struct Alice;

#[derive(derive_name::Name)]
enum Bob {
    Variant
}

let her = Alice {};
let his = Bob::Variant;

assert_eq!(her.name(), "Alice");
assert_eq!(his.name(), "Bob");

VariantName

use derive_name::VariantName;

#[derive(VariantName)]
enum Alice {
    Variant
}

assert_eq!(Alice::Variant.name(), "Variant");

Contributing

If you think you found a bug: open a issue. Feature request are also welcome.

License

This library is distributed under the terms of the ISC License.
Find an easy explanation on choosealicense.com/licenses/isc.

Dependencies

~285–740KB
~18K SLoC