Newtype ident
diff --git a/src/attr.rs b/src/attr.rs
index d2d78ed..7d7557c 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -50,7 +50,7 @@
content: take_until_s!("\n") >>
(Attribute {
value: MetaItem::NameValue(
- "doc".to_string(),
+ "doc".into(),
format!("///{}{}", space, content),
),
is_sugared_doc: true,
diff --git a/src/common.rs b/src/common.rs
index a5173d7..9c5de75 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -1,4 +1,40 @@
-pub type Ident = String;
+use std::fmt::{self, Display};
+use std::ops::Deref;
+
+#[derive(Debug, Clone, Eq, PartialEq)]
+pub struct Ident(String);
+
+impl Ident {
+ pub fn new<T: Into<Ident>>(t: T) -> Self {
+ t.into()
+ }
+}
+
+impl<'a> From<&'a str> for Ident {
+ fn from(s: &str) -> Self {
+ Ident(s.to_owned())
+ }
+}
+
+impl From<String> for Ident {
+ fn from(s: String) -> Self {
+ Ident(s)
+ }
+}
+
+impl Deref for Ident {
+ type Target = str;
+
+ fn deref(&self) -> &str {
+ &self.0
+ }
+}
+
+impl Display for Ident {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ self.0.fmt(formatter)
+ }
+}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Visibility {
@@ -16,7 +52,7 @@
named!(pub word<&str, Ident>, preceded!(
opt!(call!(::nom::multispace)),
- map!(take_while1_s!(ident_ch), String::from)
+ map!(take_while1_s!(ident_ch), Into::into)
));
named!(pub visibility<&str, Visibility>, preceded!(
diff --git a/src/generics.rs b/src/generics.rs
index a2a66a5..9b60510 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -102,7 +102,7 @@
named!(pub lifetime<&str, Lifetime>, preceded!(
punct!("'"),
map!(word, |ident| Lifetime {
- ident: format!("'{}", ident),
+ ident: format!("'{}", ident).into(),
})
));