about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-10-27 09:09:50 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-10-27 15:12:48 -0700
commit40811f84ef3f04230e29ec4feb4e99a5b79480cb (patch)
tree69cdcf0622c8bacff58133dea78a93c69a1a824b /src
parent6e9d5a6d9dd1e995f567e9b249a9e34a770f3215 (diff)
parent8a4bd8427cb4d4334e649772b2b8fc8857fd0289 (diff)
downloadrust-40811f84ef3f04230e29ec4feb4e99a5b79480cb.tar.gz
rust-40811f84ef3f04230e29ec4feb4e99a5b79480cb.zip
rollup merge of #18334 : csherratt/arc-encodable
Diffstat (limited to 'src')
-rw-r--r--src/libserialize/serialize.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs
index 3bed4e4040b..0a040fff40d 100644
--- a/src/libserialize/serialize.rs
+++ b/src/libserialize/serialize.rs
@@ -17,6 +17,7 @@ Core encoding and decoding interfaces.
 use std::path;
 use std::rc::Rc;
 use std::cell::{Cell, RefCell};
+use std::sync::Arc;
 
 pub trait Encoder<E> {
     // Primitive types:
@@ -556,6 +557,18 @@ impl<E, D: Decoder<E>, T: Decodable<D, E>> Decodable<D, E> for RefCell<T> {
     }
 }
 
+impl<E, S:Encoder<E>, T:Encodable<S, E>+Send+Sync> Encodable<S, E> for Arc<T> {
+    fn encode(&self, s: &mut S) -> Result<(), E> {
+        (**self).encode(s)
+    }
+}
+
+impl<E, D:Decoder<E>,T:Decodable<D, E>+Send+Sync> Decodable<D, E> for Arc<T> {
+    fn decode(d: &mut D) -> Result<Arc<T>, E> {
+        Ok(Arc::new(try!(Decodable::decode(d))))
+    }
+}
+
 // ___________________________________________________________________________
 // Helper routines