about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-20 03:06:29 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-22 19:45:05 +0300
commit885d2242305e5523c3cc9b459180ef5ccc19cf85 (patch)
tree73951839983fc7358aaf881d045ef0c647d7a16c /src/libsyntax
parent0c05492ee17c544600d3e1ea2740f8b398d01fc0 (diff)
downloadrust-885d2242305e5523c3cc9b459180ef5ccc19cf85.tar.gz
rust-885d2242305e5523c3cc9b459180ef5ccc19cf85.zip
Encode/decode Names as strings
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 5b04fc0e697..62eb6022d0c 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -151,8 +151,7 @@ pub const ILLEGAL_CTXT : SyntaxContext = 1;
 
 /// A name is a part of an identifier, representing a string or gensym. It's
 /// the result of interning.
-#[derive(Eq, Ord, PartialEq, PartialOrd, Hash,
-           RustcEncodable, RustcDecodable, Clone, Copy)]
+#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Clone, Copy)]
 pub struct Name(pub u32);
 
 impl<T: AsRef<str>> PartialEq<T> for Name {
@@ -179,6 +178,18 @@ impl Name {
 /// A mark represents a unique id associated with a macro expansion
 pub type Mrk = u32;
 
+impl Encodable for Name {
+    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
+        s.emit_str(&self.as_str())
+    }
+}
+
+impl Decodable for Name {
+    fn decode<D: Decoder>(d: &mut D) -> Result<Name, D::Error> {
+        Ok(token::intern(&try!(d.read_str())[..]))
+    }
+}
+
 impl Encodable for Ident {
     fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
         s.emit_str(&self.name.as_str())