Skip to content

Commit

Permalink
Relocate cfg attrs into deref_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 6, 2023
1 parent 64f949b commit 05c2509
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@ map_impl! {

macro_rules! deref_impl {
(
$(#[doc = $doc:tt])*
$(#[$attr:meta])*
<$($desc:tt)+
) => {
$(#[doc = $doc])*
$(#[$attr])*
impl <$($desc)+ {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -491,13 +491,19 @@ macro_rules! deref_impl {
};
}

deref_impl!(<'a, T: ?Sized> Serialize for &'a T where T: Serialize);
deref_impl!(<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize);
deref_impl! {
<'a, T: ?Sized> Serialize for &'a T where T: Serialize
}

#[cfg(any(feature = "std", feature = "alloc"))]
deref_impl!(<T: ?Sized> Serialize for Box<T> where T: Serialize);
deref_impl! {
<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize
}

deref_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
<T: ?Sized> Serialize for Box<T> where T: Serialize
}

#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
deref_impl! {
/// This impl requires the [`"rc"`] Cargo feature of Serde.
///
Expand All @@ -507,10 +513,10 @@ deref_impl! {
/// repeated data.
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
<T: ?Sized> Serialize for Rc<T> where T: Serialize
}

#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
deref_impl! {
/// This impl requires the [`"rc"`] Cargo feature of Serde.
///
Expand All @@ -520,11 +526,14 @@ deref_impl! {
/// repeated data.
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
<T: ?Sized> Serialize for Arc<T> where T: Serialize
}

#[cfg(any(feature = "std", feature = "alloc"))]
deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned);
deref_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned
}

////////////////////////////////////////////////////////////////////////////////

Expand Down

0 comments on commit 05c2509

Please sign in to comment.