Skip to content

Commit

Permalink
Added Encodable and Decodable for Arc<T>.
Browse files Browse the repository at this point in the history
  • Loading branch information
csherratt committed Oct 27, 2014
1 parent f168c12 commit 8a4bd84
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/libserialize/serialize.rs
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8a4bd84

Please sign in to comment.