AsRef instead of Deref to prevent accidental quoting
diff --git a/src/attr.rs b/src/attr.rs
index 7d7557c..dc43805 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -100,15 +100,17 @@
impl ToTokens for MetaItem {
fn to_tokens(&self, tokens: &mut Tokens) {
match *self {
- MetaItem::Word(ref ident) => tokens.append(&ident),
+ MetaItem::Word(ref ident) => {
+ ident.to_tokens(tokens);
+ }
MetaItem::List(ref ident, ref inner) => {
- tokens.append(&ident);
+ ident.to_tokens(tokens);
tokens.append("(");
tokens.append_separated(inner, ",");
tokens.append(")");
}
MetaItem::NameValue(ref name, ref value) => {
- tokens.append(&name);
+ name.to_tokens(tokens);
tokens.append("=");
value.to_tokens(tokens);
}
diff --git a/src/common.rs b/src/common.rs
index 9c5de75..b2f498d 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -1,5 +1,4 @@
use std::fmt::{self, Display};
-use std::ops::Deref;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Ident(String);
@@ -22,10 +21,8 @@
}
}
-impl Deref for Ident {
- type Target = str;
-
- fn deref(&self) -> &str {
+impl AsRef<str> for Ident {
+ fn as_ref(&self) -> &str {
&self.0
}
}
@@ -64,3 +61,15 @@
)
));
}
+
+#[cfg(feature = "printing")]
+mod printing {
+ use super::*;
+ use quote::{Tokens, ToTokens};
+
+ impl ToTokens for Ident {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ tokens.append(self.as_ref())
+ }
+ }
+}