Add an implementation of Encodable and Decodable for Rc. This will be needed to use Rc in place of @ in libsyntax.

This commit is contained in:
Léo Testard 2013-11-25 19:35:03 +01:00
parent 01b5381703
commit b6ab4f2485
1 changed files with 15 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Core encoding and decoding interfaces.
use std::at_vec;
use std::hashmap::{HashMap, HashSet};
use std::rc::Rc;
use std::trie::{TrieMap, TrieSet};
use std::vec;
use ringbuf::RingBuf;
@ -405,6 +406,20 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
}
}
impl<S:Encoder,T:Encodable<S> + Freeze> Encodable<S> for Rc<T> {
#[inline]
fn encode(&self, s: &mut S) {
self.borrow().encode(s)
}
}
impl<D:Decoder,T:Decodable<D> + Freeze> Decodable<D> for Rc<T> {
#[inline]
fn decode(d: &mut D) -> Rc<T> {
Rc::new(Decodable::decode(d))
}
}
impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @T {
fn decode(d: &mut D) -> @T {
@Decodable::decode(d)