A library for generating #[...]
and pub
code in item declarations.
Suppose you needed the following code:
```rust
pub struct Foo( #[apple] pub i32, #[apple] pub i32, );
pub enum Bar { #[orange] X(i32), #[orange] Y(i32), }
pub struct Baz( #[apple] pub i32, #[apple] pub f32, #[apple] pub i32, );
pub enum Qux { #[orange] A(i32), #[orange] B(i32), #[orange] C(i32), } ```
Instead of typing out #[orange]
, #[apple]
, and pub
, repeatedly for each item declaration, you could simply write:
```rust use deriveless::deriveless;
derive_less! { #[derive(Debug)] pub struct ... { #[apple] pub ... } #[derive(Clone)] pub enum ... { #[orange] ... }
struct Foo(i32, i32);
enum Bar {
X(i32),
Y(i32),
}
struct Baz(i32, f32, i32);
enum Qux {
A(i32),
B(i32),
C(i32),
}
} ```
You can also mix in derives that only apply to certain items/variants/fields, e.g:
```rust use deriveless::deriveless;
derive_less! { #[derive(Debug)] pub struct ... { #[apple] pub ... } #[derive(Clone)] pub enum ... { #[orange] ... }
struct Foo(i32, i32);
enum Bar {
X(#[peanut] i32),
Y(i32),
}
#[derive(PartialEq, PartialOrd)]
struct Baz(i32, f32, i32);
enum Qux {
A(i32),
B(i32),
C(i32),
}
} ```
Currently only supports: * Tuple structs * Unit structs * Enums with unnamed or unit fields
While structs and enums can take multiple #[...]
, e.g.:
```
```
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] ... }
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.