Skip to content

Commit 885d224

Browse files
committed
Encode/decode Names as strings
1 parent 0c05492 commit 885d224

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/libsyntax/ast.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ pub const ILLEGAL_CTXT : SyntaxContext = 1;
151151

152152
/// A name is a part of an identifier, representing a string or gensym. It's
153153
/// the result of interning.
154-
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash,
155-
RustcEncodable, RustcDecodable, Clone, Copy)]
154+
#[derive(Eq, Ord, PartialEq, PartialOrd, Hash, Clone, Copy)]
156155
pub struct Name(pub u32);
157156

158157
impl<T: AsRef<str>> PartialEq<T> for Name {
@@ -179,6 +178,18 @@ impl Name {
179178
/// A mark represents a unique id associated with a macro expansion
180179
pub type Mrk = u32;
181180

181+
impl Encodable for Name {
182+
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
183+
s.emit_str(&self.as_str())
184+
}
185+
}
186+
187+
impl Decodable for Name {
188+
fn decode<D: Decoder>(d: &mut D) -> Result<Name, D::Error> {
189+
Ok(token::intern(&try!(d.read_str())[..]))
190+
}
191+
}
192+
182193
impl Encodable for Ident {
183194
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
184195
s.emit_str(&self.name.as_str())

0 commit comments

Comments
 (0)