Add impls for Cow

This commit is contained in:
Skyler Lipthay 2015-06-19 22:40:03 -07:00
parent ed5b4d7319
commit 36fb49b522
2 changed files with 21 additions and 0 deletions

View File

@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::hash::Hash;
use std::marker::PhantomData;
@ -854,3 +855,13 @@ impl<T: Deserialize> Deserialize for Rc<T> {
Ok(Rc::new(val))
}
}
impl<'a, T: ?Sized> Deserialize for Cow<'a, T> where T: ToOwned, T::Owned: Deserialize, {
#[inline]
fn deserialize<D>(deserializer: &mut D) -> Result<Cow<'a, T>, D::Error>
where D: Deserializer,
{
let val = try!(Deserialize::deserialize(deserializer));
Ok(Cow::Owned(val))
}
}

View File

@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::hash::Hash;
use std::path;
@ -518,6 +519,15 @@ impl<T> Serialize for Arc<T> where T: Serialize, {
}
}
impl<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned, {
#[inline]
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer,
{
(**self).serialize(serializer)
}
}
///////////////////////////////////////////////////////////////////////////////
impl Serialize for path::Path {