]> git.lizzy.rs Git - rust.git/commitdiff
Added Encodable and Decodable for Arc<T>.
authorColin Sherratt <colin.sherratt@gmail.com>
Sun, 26 Oct 2014 03:38:27 +0000 (23:38 -0400)
committerColin Sherratt <colin.sherratt@gmail.com>
Mon, 27 Oct 2014 03:41:51 +0000 (23:41 -0400)
src/libserialize/serialize.rs

index 3bed4e4040b3a1267c6a5ba57a6951b8bb3ee9f8..0a040fff40d6a4b55b3ef618490f6b669c080be5 100644 (file)
@@ -17,6 +17,7 @@
 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 @@ fn decode(d: &mut D) -> Result<RefCell<T>, E> {
     }
 }
 
+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