Derive Macro EnumDescriptor

Source
#[derive(EnumDescriptor)]
{
    // Attributes available to this derive:
    #[arg_description]
}
Expand description

A derive procedural macro for the EnumDescriptor trait.

The EnumDescriptor trait should have a function name_with_token_count that returns a tuple with the name of the enum type as a string and the token count for the name as an usize.

This procedural macro generates an implementation of EnumDescriptor for the type on which it’s applied. The name_with_token_count function, in the generated implementation, returns the name of the type and its token count.

§Usage

Use the #[derive(EnumDescriptor)] attribute on an enum to derive the EnumDescriptor trait for it.

#[derive(EnumDescriptor)]
enum MyEnum {
    Variant1,
    Variant2,
}

This will generate:

impl EnumDescriptor for MyEnum {
    fn name_with_token_count() -> (String, usize) {
        (String::from("MyEnum"), /* token count of "MyEnum" */)
    }
}

The actual token count is computed during compile time using the calculate_token_count function.