From: Vadim Petrochenkov Date: Sun, 20 Sep 2015 00:06:29 +0000 (+0300) Subject: Encode/decode Names as strings X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=885d2242305e5523c3cc9b459180ef5ccc19cf85;p=rust.git Encode/decode Names as strings --- 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 @@ 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> PartialEq 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(&self, s: &mut S) -> Result<(), S::Error> { + s.emit_str(&self.as_str()) + } +} + +impl Decodable for Name { + fn decode(d: &mut D) -> Result { + Ok(token::intern(&try!(d.read_str())[..])) + } +} + impl Encodable for Ident { fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_str(&self.name.as_str())