auto merge of #10658 : LeoTestard/rust/serialize-rc, r=cmr

Implement various traits (IterBytes and extra's Encodable and Decodable) for Rc<T> when T alreay implements the trait.
This commit is contained in:
bors 2013-11-25 13:11:43 -08:00
commit e632c440f8
2 changed files with 23 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)

View File

@ -18,6 +18,7 @@ use cast;
use container::Container;
use iter::Iterator;
use option::{None, Option, Some};
use rc::Rc;
use str::{Str, StrSlice};
use vec::{Vector, ImmutableVector};
@ -325,6 +326,13 @@ impl<A:IterBytes> IterBytes for @mut A {
}
}
impl<A:IterBytes> IterBytes for Rc<A> {
#[inline]
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
self.borrow().iter_bytes(lsb0, f)
}
}
impl<A:IterBytes> IterBytes for ~A {
#[inline]
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {