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/attr.rs b/src/attr.rs
index fecfd9a..f839ec4 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -133,7 +133,7 @@
/// Distinguishes between Attributes that decorate items and Attributes that
/// are contained as statements within items. These two cases need to be
/// distinguished for pretty-printing.
- #[derive(Copy)]
+ #[cfg_attr(feature = "clone-impls", derive(Copy))]
pub enum AttrStyle {
/// Attribute of the form `#![...]`.
Outer,
@@ -230,14 +230,20 @@
fn outer(self) -> Self::Ret {
fn is_outer(attr: &&Attribute) -> bool {
- attr.style == AttrStyle::Outer
+ match attr.style {
+ AttrStyle::Outer => true,
+ _ => false,
+ }
}
self.into_iter().filter(is_outer)
}
fn inner(self) -> Self::Ret {
fn is_inner(attr: &&Attribute) -> bool {
- attr.style == AttrStyle::Inner
+ match attr.style {
+ AttrStyle::Inner => true,
+ _ => false,
+ }
}
self.into_iter().filter(is_inner)
}
@@ -369,7 +375,7 @@
// If this was a sugared doc, emit it in its original form instead of `#[doc = "..."]`
match *self {
Attribute {
- style,
+ ref style,
path: Path { global: false, ref segments },
ref tts,
is_sugared_doc: true,
@@ -380,7 +386,7 @@
{
if let TokenTree::Token(Token::Eq) = self.tts[0] {
if let TokenTree::Token(Token::Literal(Lit::Str(ref value, StrStyle::Cooked))) = self.tts[1] {
- match style {
+ match *style {
AttrStyle::Inner if value.starts_with("//!") => {
tokens.append(&format!("{}\n", value));
return;