Skip to content

Commit

Permalink
Add an implementation of Encodable and Decodable for Rc. This will be…
Browse files Browse the repository at this point in the history
… needed to use Rc in place of @ in libsyntax.
  • Loading branch information
LeoTestard committed Nov 25, 2013
1 parent 01b5381 commit b6ab4f2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libextra/serialize.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b6ab4f2

Please sign in to comment.