about summary refs log tree commit diff
path: root/src/libsyntax/ast.rs
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2014-07-06 01:17:59 -0700
committerCorey Richardson <corey@octayn.net>2014-07-09 00:49:54 -0700
commit092c5078be5b9abfc4e1a80e3ef9d015d321479c (patch)
tree46b19fe160154e14c412e928e676daa809407913 /src/libsyntax/ast.rs
parentf512779554a436d11dd9ffde4c198da6241dfd58 (diff)
downloadrust-092c5078be5b9abfc4e1a80e3ef9d015d321479c.tar.gz
rust-092c5078be5b9abfc4e1a80e3ef9d015d321479c.zip
ast: make Name its own type
Diffstat (limited to 'src/libsyntax/ast.rs')
-rw-r--r--src/libsyntax/ast.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 2a49d0e0f5b..ebfc45d22ce 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -52,10 +52,7 @@ impl Ident {
     pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}}
 
     pub fn as_str<'a>(&'a self) -> &'a str {
-        unsafe {
-            // FIXME #12938: can't use copy_lifetime since &str isn't a &T
-            ::std::mem::transmute(token::get_ident(*self).get())
-        }
+        self.name.as_str()
     }
 }
 
@@ -109,7 +106,26 @@ pub static ILLEGAL_CTXT : SyntaxContext = 1;
 
 /// A name is a part of an identifier, representing a string or gensym. It's
 /// the result of interning.
-pub type Name = u32;
+#[deriving(Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone, Show)]
+pub struct Name(pub u32);
+
+impl Name {
+    pub fn as_str<'a>(&'a self) -> &'a str {
+        unsafe {
+            // FIXME #12938: can't use copy_lifetime since &str isn't a &T
+            ::std::mem::transmute(token::get_name(*self).get())
+        }
+    }
+
+    pub fn uint(&self) -> uint {
+        let Name(nm) = *self;
+        nm as uint
+    }
+
+    pub fn ident(&self) -> Ident {
+        Ident { name: *self, ctxt: 0 }
+    }
+}
 
 /// A mark represents a unique id associated with a macro expansion
 pub type Mrk = u32;