From b6ab4f2485c5e4bc6c18868c4e4c522404f77b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81o=20Testard?= Date: Mon, 25 Nov 2013 19:35:03 +0100 Subject: [PATCH 1/2] Add an implementation of Encodable and Decodable for Rc. This will be needed to use Rc in place of @ in libsyntax. --- src/libextra/serialize.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index 8e75be651cfa6..9b0e00a41e508 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -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> Encodable for @T { } } +impl + Freeze> Encodable for Rc { + #[inline] + fn encode(&self, s: &mut S) { + self.borrow().encode(s) + } +} + +impl + Freeze> Decodable for Rc { + #[inline] + fn decode(d: &mut D) -> Rc { + Rc::new(Decodable::decode(d)) + } +} + impl + 'static> Decodable for @T { fn decode(d: &mut D) -> @T { @Decodable::decode(d) From ae836c1e44d7459d4588e622a8535f127e32716f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81o=20Testard?= Date: Mon, 25 Nov 2013 19:47:09 +0100 Subject: [PATCH 2/2] Implement IterBytes for Rc. --- src/libstd/to_bytes.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 8b424c53be0b8..28b79bdd320b4 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -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 IterBytes for @mut A { } } +impl IterBytes for Rc { + #[inline] + fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { + self.borrow().iter_bytes(lsb0, f) + } +} + impl IterBytes for ~A { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {