macro_rules! impl_serialize_to_string {
($ty:ty) => {
impl Serialize for $ty {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer
{
serializer.serialize_str(&self.to_string())
}
}
}
}
macro_rules! impl_deserialize_from_str {
($ty:ty) => {
impl Deserialize for $ty {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
where D: Deserializer
{
let string = try!(String::deserialize(deserializer));
Self::from_str(&string).map_err(|err| {
de::Error::custom(format!("{}", err))
})
}
}
}
}