Skip to content

Commit 40811f8

Browse files
committed
rollup merge of #18334 : csherratt/arc-encodable
2 parents 6e9d5a6 + 8a4bd84 commit 40811f8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libserialize/serialize.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Core encoding and decoding interfaces.
1717
use std::path;
1818
use std::rc::Rc;
1919
use std::cell::{Cell, RefCell};
20+
use std::sync::Arc;
2021

2122
pub trait Encoder<E> {
2223
// Primitive types:
@@ -556,6 +557,18 @@ impl<E, D: Decoder<E>, T: Decodable<D, E>> Decodable<D, E> for RefCell<T> {
556557
}
557558
}
558559

560+
impl<E, S:Encoder<E>, T:Encodable<S, E>+Send+Sync> Encodable<S, E> for Arc<T> {
561+
fn encode(&self, s: &mut S) -> Result<(), E> {
562+
(**self).encode(s)
563+
}
564+
}
565+
566+
impl<E, D:Decoder<E>,T:Decodable<D, E>+Send+Sync> Decodable<D, E> for Arc<T> {
567+
fn decode(d: &mut D) -> Result<Arc<T>, E> {
568+
Ok(Arc::new(try!(Decodable::decode(d))))
569+
}
570+
}
571+
559572
// ___________________________________________________________________________
560573
// Helper routines
561574

0 commit comments

Comments
 (0)