Skip to content

Commit b6ab4f2

Browse files
committed
Add an implementation of Encodable and Decodable for Rc. This will be needed to use Rc in place of @ in libsyntax.
1 parent 01b5381 commit b6ab4f2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libextra/serialize.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Core encoding and decoding interfaces.
2020

2121
use std::at_vec;
2222
use std::hashmap::{HashMap, HashSet};
23+
use std::rc::Rc;
2324
use std::trie::{TrieMap, TrieSet};
2425
use std::vec;
2526
use ringbuf::RingBuf;
@@ -405,6 +406,20 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
405406
}
406407
}
407408

409+
impl<S:Encoder,T:Encodable<S> + Freeze> Encodable<S> for Rc<T> {
410+
#[inline]
411+
fn encode(&self, s: &mut S) {
412+
self.borrow().encode(s)
413+
}
414+
}
415+
416+
impl<D:Decoder,T:Decodable<D> + Freeze> Decodable<D> for Rc<T> {
417+
#[inline]
418+
fn decode(d: &mut D) -> Rc<T> {
419+
Rc::new(Decodable::decode(d))
420+
}
421+
}
422+
408423
impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @T {
409424
fn decode(d: &mut D) -> @T {
410425
@Decodable::decode(d)

0 commit comments

Comments
 (0)