Add verbatim variants as an escape hatch
diff --git a/src/item.rs b/src/item.rs
index 74ed612..0672dcc 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -1,9 +1,9 @@
use super::*;
use delimited::Delimited;
-use proc_macro2::TokenTree;
+use proc_macro2::{TokenTree, TokenStream};
#[cfg(feature = "extra-traits")]
-use mac::TokenTreeHelper;
+use mac::{TokenTreeHelper, TokenStreamHelper};
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
@@ -207,6 +207,9 @@
pub args: TokenTree,
pub body: TokenTree,
}),
+ pub Verbatim(ItemVerbatim #manual_extra_traits {
+ pub tts: TokenStream,
+ }),
}
}
@@ -238,6 +241,26 @@
}
}
+#[cfg(feature = "extra-traits")]
+impl Eq for ItemVerbatim {}
+
+#[cfg(feature = "extra-traits")]
+impl PartialEq for ItemVerbatim {
+ fn eq(&self, other: &Self) -> bool {
+ TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
+ }
+}
+
+#[cfg(feature = "extra-traits")]
+impl Hash for ItemVerbatim {
+ fn hash<H>(&self, state: &mut H)
+ where
+ H: Hasher,
+ {
+ TokenStreamHelper(&self.tts).hash(state);
+ }
+}
+
impl From<DeriveInput> for Item {
fn from(input: DeriveInput) -> Item {
match input.body {
@@ -313,6 +336,29 @@
pub ident: Ident,
pub semi_token: Token![;],
}),
+ pub Verbatim(ForeignItemVerbatim #manual_extra_traits {
+ pub tts: TokenStream,
+ }),
+ }
+}
+
+#[cfg(feature = "extra-traits")]
+impl Eq for ForeignItemVerbatim {}
+
+#[cfg(feature = "extra-traits")]
+impl PartialEq for ForeignItemVerbatim {
+ fn eq(&self, other: &Self) -> bool {
+ TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
+ }
+}
+
+#[cfg(feature = "extra-traits")]
+impl Hash for ForeignItemVerbatim {
+ fn hash<H>(&self, state: &mut H)
+ where
+ H: Hasher,
+ {
+ TokenStreamHelper(&self.tts).hash(state);
}
}
@@ -352,6 +398,29 @@
pub mac: Macro,
pub semi_token: Option<Token![;]>,
}),
+ pub Verbatim(TraitItemVerbatim #manual_extra_traits {
+ pub tts: TokenStream,
+ }),
+ }
+}
+
+#[cfg(feature = "extra-traits")]
+impl Eq for TraitItemVerbatim {}
+
+#[cfg(feature = "extra-traits")]
+impl PartialEq for TraitItemVerbatim {
+ fn eq(&self, other: &Self) -> bool {
+ TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
+ }
+}
+
+#[cfg(feature = "extra-traits")]
+impl Hash for TraitItemVerbatim {
+ fn hash<H>(&self, state: &mut H)
+ where
+ H: Hasher,
+ {
+ TokenStreamHelper(&self.tts).hash(state);
}
}
@@ -392,6 +461,29 @@
pub mac: Macro,
pub semi_token: Option<Token![;]>,
}),
+ pub Verbatim(ImplItemVerbatim #manual_extra_traits {
+ pub tts: TokenStream,
+ }),
+ }
+}
+
+#[cfg(feature = "extra-traits")]
+impl Eq for ImplItemVerbatim {}
+
+#[cfg(feature = "extra-traits")]
+impl PartialEq for ImplItemVerbatim {
+ fn eq(&self, other: &Self) -> bool {
+ TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts)
+ }
+}
+
+#[cfg(feature = "extra-traits")]
+impl Hash for ImplItemVerbatim {
+ fn hash<H>(&self, state: &mut H)
+ where
+ H: Hasher,
+ {
+ TokenStreamHelper(&self.tts).hash(state);
}
}
@@ -1532,6 +1624,12 @@
}
}
+ impl ToTokens for ItemVerbatim {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.tts.to_tokens(tokens);
+ }
+ }
+
impl ToTokens for UsePath {
fn to_tokens(&self, tokens: &mut Tokens) {
self.ident.to_tokens(tokens);
@@ -1616,6 +1714,12 @@
}
}
+ impl ToTokens for TraitItemVerbatim {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.tts.to_tokens(tokens);
+ }
+ }
+
impl ToTokens for ImplItemConst {
fn to_tokens(&self, tokens: &mut Tokens) {
tokens.append_all(self.attrs.outer());
@@ -1666,6 +1770,12 @@
}
}
+ impl ToTokens for ImplItemVerbatim {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.tts.to_tokens(tokens);
+ }
+ }
+
impl ToTokens for ForeignItemFn {
fn to_tokens(&self, tokens: &mut Tokens) {
tokens.append_all(self.attrs.outer());
@@ -1698,6 +1808,12 @@
}
}
+ impl ToTokens for ForeignItemVerbatim {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.tts.to_tokens(tokens);
+ }
+ }
+
impl ToTokens for MethodSig {
fn to_tokens(&self, tokens: &mut Tokens) {
self.constness.to_tokens(tokens);