]> git.lizzy.rs Git - rust.git/commitdiff
Encode/decode Names as strings
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 20 Sep 2015 00:06:29 +0000 (03:06 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 22 Sep 2015 16:45:05 +0000 (19:45 +0300)
src/libsyntax/ast.rs

index 5b04fc0e6977b3ece9c9f1d26f31702b70ca088b..62eb6022d0c22c8045ca4f0b0321efbf5ae15873 100644 (file)
@@ -151,8 +151,7 @@ fn eq(&self, other: &Ident) -> bool {
 
 /// 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 @@ pub fn ident(&self) -> Ident {
 /// 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())