derive_less
A library for generating #[...]
and pub
code in item declarations.
Example
Suppose you needed the following code:
;
;
Instead of typing out #[orange]
, #[apple]
, and pub
, repeatedly for each item declaration, you could simply write:
use derive_less;
derive_less!
You can also mix in derives that only apply to certain items/variants/fields, e.g:
use derive_less;
derive_less!
Limitations
Currently only supports:
- Tuple structs
- Unit structs
- Regular structs
- Enums with unnamed or unit fields
- Enums with (only) named fields
While structs and enums can take multiple #[...]
, e.g.:
#[hello] #[world] struct ... { ... }
Fields and variants accept at most one #[...]
due to current restrictions in macro_rules!
. In other words, this does not work at the moment:
struct ... { #[hello] #[world] ... }
Future work
Handle more cases by either rewriting the derive_less!
macro using Rust's procedural macro interface or through a build-script that generates declarative macro code.