Crates.io | derive_less |
lib.rs | derive_less |
version | 0.2.0 |
source | src |
created_at | 2019-04-15 15:09:37.447997 |
updated_at | 2019-07-07 14:35:12.337168 |
description | A macro for templating item declarations. |
homepage | https://github.com/segeljakt/derive_less |
repository | https://github.com/segeljakt/derive_less |
max_upload_size | |
id | 128119 |
size | 12,317 |
A macro for templating item declarations.
Suppose you needed the following code:
#[derive(Debug)]
pub struct Foo(
#[apple]
pub i32,
#[apple]
pub i32,
);
#[derive(Clone)]
pub enum Bar {
#[orange]
X(i32),
#[orange]
Y(i32),
}
#[derive(Debug)]
pub struct Baz(
#[apple]
pub i32,
#[apple]
pub f32,
#[apple]
pub i32,
);
#[derive(Clone)]
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:
use derive_less::derive_less;
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:
use derive_less::derive_less;
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),
}
}