diff --git a/src/de.rs b/src/de.rs index a2607c36..8882a66c 100644 --- a/src/de.rs +++ b/src/de.rs @@ -9,8 +9,11 @@ // except according to those terms. use std::collections::{HashMap, TreeMap}; +use std::gc::{GC, Gc}; use std::hash::Hash; use std::num; +use std::rc::Rc; +use std::sync::Arc; #[deriving(Clone, PartialEq, Show)] pub enum Token { @@ -471,6 +474,48 @@ impl_deserializable!(String, expect_string) ////////////////////////////////////////////////////////////////////////////// +impl Deserializable for Box { + #[inline] + fn deserialize_token< + D: Deserializer, + E + >(d: &mut D, token: Token) -> Result, E> { + Ok(box try!(Deserializable::deserialize_token(d, token))) + } +} + +impl Deserializable for Gc { + #[inline] + fn deserialize_token< + D: Deserializer, + E + >(d: &mut D, token: Token) -> Result, E> { + Ok(box (GC) try!(Deserializable::deserialize_token(d, token))) + } +} + +impl Deserializable for Rc { + #[inline] + fn deserialize_token< + D: Deserializer, + E + >(d: &mut D, token: Token) -> Result, E> { + Ok(Rc::new(try!(Deserializable::deserialize_token(d, token)))) + } +} + +impl Deserializable for Arc { + #[inline] + fn deserialize_token< + D: Deserializer, + E + >(d: &mut D, token: Token) -> Result, E> { + Ok(Arc::new(try!(Deserializable::deserialize_token(d, token)))) + } +} + +////////////////////////////////////////////////////////////////////////////// + impl Deserializable for Option { #[inline] fn deserialize_token< diff --git a/src/ser.rs b/src/ser.rs index 719f4ab3..c5483834 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -9,7 +9,10 @@ // except according to those terms. use std::collections::{HashMap, TreeMap}; +use std::gc::Gc; use std::hash::Hash; +use std::rc::Rc; +use std::sync::Arc; ////////////////////////////////////////////////////////////////////////////// @@ -162,19 +165,23 @@ impl Serializable for String { ////////////////////////////////////////////////////////////////////////////// -impl< - 'a, - T: Serializable -> Serializable for &'a T { - #[inline] - fn serialize< - S: Serializer, - E - >(&self, s: &mut S) -> Result<(), E> { - (*self).serialize(s) +macro_rules! impl_serializable_box { + ($ty:ty) => { + impl<'a, T: Serializable> Serializable for $ty { + #[inline] + fn serialize, E>(&self, s: &mut S) -> Result<(), E> { + (*self).serialize(s) + } + } } } +impl_serializable_box!(&'a T) +impl_serializable_box!(Box) +impl_serializable_box!(Gc) +impl_serializable_box!(Rc) +impl_serializable_box!(Arc) + ////////////////////////////////////////////////////////////////////////////// impl<