Move all #[derive] impls behind Cargo feature gates
This commit moves all #[derive] annotations behind Cargo feature gates to add
the ability to strip them all out entirely. The `Clone` and `Copy` impls
continue to be enabled by default as they tend to be mega useful but other
equality/hash/debug impls are all default behind the `extra-impls` gate.
This commit, on my computer, has the following timings:
| features | before | after
|-------------------------------|---------|------
| default | 3.67 | 2.96
| *none* | 1.78 | 0.49
| {printing, parsing} | 3.71 | 2.57
| default + {full} | 8.50 | 6.31
| {full} | 3.53 | 0.70
| {full, printing, parsing} | 8.10 | 5.29
Closes #143
diff --git a/src/lit.rs b/src/lit.rs
index 4811485..72a2f43 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -2,6 +2,7 @@
/// Literal kind.
///
/// E.g. `"foo"`, `42`, `12.34` or `bool`
+ #[cfg_attr(not(feature = "clone-impls"), derive(Clone))]
pub enum Lit {
/// A string literal (`"foo"`)
Str(String, StrStyle),
@@ -21,6 +22,7 @@
}
ast_enum! {
+ #[cfg_attr(not(feature = "clone-impls"), derive(Clone))]
pub enum StrStyle {
/// A regular string, like `"foo"`
Cooked,
@@ -69,6 +71,7 @@
ast_enum! {
#[derive(Copy)]
+ #[cfg_attr(not(feature = "clone-impls"), derive(Clone))]
pub enum IntTy {
Isize,
I8,
@@ -86,6 +89,7 @@
ast_enum! {
#[derive(Copy)]
+ #[cfg_attr(not(feature = "clone-impls"), derive(Clone))]
pub enum FloatTy {
F32,
F64,
@@ -133,31 +137,35 @@
]}
#[cfg(feature = "parsing")]
-#[derive(Debug, Clone)]
-pub struct StrLit {
- pub value: String,
- pub style: StrStyle,
+ast_struct! {
+ pub struct StrLit {
+ pub value: String,
+ pub style: StrStyle,
+ }
}
#[cfg(feature = "parsing")]
-#[derive(Debug, Clone)]
-pub struct ByteStrLit {
- pub value: Vec<u8>,
- pub style: StrStyle,
+ast_struct! {
+ pub struct ByteStrLit {
+ pub value: Vec<u8>,
+ pub style: StrStyle,
+ }
}
#[cfg(feature = "parsing")]
-#[derive(Debug, Clone)]
-pub struct IntLit {
- pub value: u64,
- pub suffix: IntTy,
+ast_struct! {
+ pub struct IntLit {
+ pub value: u64,
+ pub suffix: IntTy,
+ }
}
#[cfg(feature = "parsing")]
-#[derive(Debug, Clone)]
-pub struct FloatLit {
- pub value: String,
- pub suffix: FloatTy,
+ast_struct! {
+ pub struct FloatLit {
+ pub value: String,
+ pub suffix: FloatTy,
+ }
}
#[cfg(feature = "parsing")]