Custom Attrs
A library that allows you to configure values specific to each variants of an enum.
Installation and Usage
Add this to your Cargo.toml file :
[]
= "1.4"
Then you can use the derive attribute to use the library.
use CustomAttrs;
// all attributes declarations will be here.
Attribute declaration.
By default, an attribute declaration is composed of two parts : an attribute's name and it's type.
You can declare many attribute declarations in a single attr.
Optionally, you can add more components.
Optional components
You can set the visibility of the attribute. This will change the visibility of the getter function.
By default, each attribute declared require a value to be set for each variant. If this requirement is not set, the library will produce an error.
You can disable this behavior by making it optional, by writing type into an Option, or by adding a default value behind the attribute declaration. See the example below.
You can add documentation avoid declared attributes. This documentation will override the one of the getter function.
Setting a value
To set a value for a variant, just add the name of the attribute followed by the value you want to set.
Like declarations, you can set many values at once.
If the attribute is optional, you don't have to wrap it in a Some. custom_attrs will do this for you. If you want the value to be None, just put None behind the it.
Getting a value attribute
To get the value from a variant, simple call get_<attribute name>.
VariantA.get_a;
If you've set a documentation on the attribute, it will be shown on this function.
Examples
use CustomAttrs;
// ...
See the examples directory for more details.
License
Licensed under the MIT license.