Condense the deref impls

This commit is contained in:
David Tolnay 2017-04-13 16:26:30 -07:00
parent f28abe8fde
commit f45b83f0c1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -302,10 +302,9 @@ map_impl!(HashMap<K: Eq + Hash, V, H: BuildHasher>);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
impl<'a, T: ?Sized> Serialize for &'a T macro_rules! deref_impl {
where ($($desc:tt)+) => {
T: Serialize, impl $($desc)+ {
{
#[inline] #[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
@ -313,76 +312,24 @@ where
{ {
(**self).serialize(serializer) (**self).serialize(serializer)
} }
}
};
} }
impl<'a, T: ?Sized> Serialize for &'a mut T deref_impl!(<'a, T: ?Sized> Serialize for &'a T where T: Serialize);
where deref_impl!(<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize);
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
(**self).serialize(serializer)
}
}
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
impl<T: ?Sized> Serialize for Box<T> deref_impl!(<T: ?Sized> Serialize for Box<T> where T: Serialize);
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
(**self).serialize(serializer)
}
}
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<T> Serialize for Rc<T> deref_impl!(<T> Serialize for Rc<T> where T: Serialize);
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
(**self).serialize(serializer)
}
}
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<T> Serialize for Arc<T> deref_impl!(<T> Serialize for Arc<T> where T: Serialize);
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
(**self).serialize(serializer)
}
}
#[cfg(any(feature = "std", feature = "collections"))] #[cfg(any(feature = "std", feature = "collections"))]
impl<'a, T: ?Sized> Serialize for Cow<'a, T> deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned);
where
T: Serialize + ToOwned,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
(**self).serialize(serializer)
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////