| Crates.io | gratte |
| lib.rs | gratte |
| version | 1.2.0 |
| created_at | 2025-03-29 22:55:50.101717+00 |
| updated_at | 2025-07-27 13:14:56.539833+00 |
| description | Helpful macros for working with enums and strings; forked from strum |
| homepage | https://github.com/clechasseur/gratte#readme |
| repository | https://github.com/clechasseur/gratte |
| max_upload_size | |
| id | 1611809 |
| size | 27,463 |
gratte (a strum fork)gratte is a fork of strum.
It defines a set of macros and traits for working with enums and strings easier in Rust.
Good question.
My motivation when creating this fork was to be able to add new features more quickly. It was also a good opportunity to learn more about proc macros in Rust.
However, fragmentation can be dangerous.
Ultimately, I would like for gratte's new features to be backported to strum.
I will try to create PRs for this to happen.
However, I cannot guarantee that strum's maintainer will accept them.
Unless you have a specific need for something new in gratte, I would probably stick with strum.
But if you need one of gratte's new features, then by all means use this 🙂
Add gratte to your dependencies:
[dependencies]
gratte = "1.1.0"
or by running:
cargo add gratte
gratte has the following derive macros:
| Macro | Description |
|---|---|
| EnumString | Converts strings to enum variants based on their name. |
| Display | Converts enum variants to strings |
| FromRepr | Convert from an integer to an enum. |
| AsRefStr | Implement AsRef<str> for MyEnum |
| IntoStaticStr | Implements From<MyEnum> for &'static str on an enum |
| EnumIter | Creates a new type that iterates the variants of an enum. |
| EnumProperty | Add custom properties to enum variants. |
| EnumMessage | Add a verbose message to enum variants. |
| EnumDiscriminants | Generate a new type with only the discriminant names. |
| EnumCount | Add a constant usize equal to the number of variants. |
| VariantArray | Adds an associated VARIANTS constant which is an array of all enum discriminants |
| VariantNames | Adds an associated VARIANTS constant which is an array of discriminant names |
To see the generated code, set the STRUM_DEBUG environment variable before compiling your code.
STRUM_DEBUG=1 will dump all the generated code for every type.
STRUM_DEBUG=YourType will only dump the code generated on a type named YourType.
strumderive feature of the gratte crate is enabled by default.#[automatically_derived] attribute.
strum has this for some of the code but not all (for now).#[strum_discriminants(non_exhaustive)])#[strum_discriminants(doc = "foo")])For instructions on filing bug reports or feature requests and contributing to the project, see CONTRIBUTING.
gratte currently builds on Rust 1.66.1 or newer.
gratte?gratte is the French translation of strum.
(For more information on the original name, see the project page. 🙂)