diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 20652af3..672a23a5 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -470,7 +470,11 @@ impl<'de> Deserialize<'de> for CString { } macro_rules! forwarded_impl { - (( $($id: ident),* ), $ty: ty, $func: expr) => { + ( + $(#[doc = $doc:tt])* + ( $($id: ident),* ), $ty: ty, $func: expr + ) => { + $(#[doc = $doc])* impl<'de $(, $id : Deserialize<'de>,)*> Deserialize<'de> for $ty { fn deserialize(deserializer: D) -> Result where @@ -1432,10 +1436,28 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice); forwarded_impl!((), Box, String::into_boxed_str); #[cfg(all(not(feature = "unstable"), feature = "rc", any(feature = "std", feature = "alloc")))] -forwarded_impl!((T), Arc, Arc::new); +forwarded_impl! { + /// This impl requires the [`"rc"`] Cargo feature of Serde. + /// + /// Deserializing a data structure containing `Arc` will not attempt to + /// deduplicate `Arc` references to the same data. Every deserialized `Arc` + /// will end up with a strong count of 1. + /// + /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc + (T), Arc, Arc::new +} #[cfg(all(not(feature = "unstable"), feature = "rc", any(feature = "std", feature = "alloc")))] -forwarded_impl!((T), Rc, Rc::new); +forwarded_impl! { + /// This impl requires the [`"rc"`] Cargo feature of Serde. + /// + /// Deserializing a data structure containing `Rc` will not attempt to + /// deduplicate `Rc` references to the same data. Every deserialized `Rc` + /// will end up with a strong count of 1. + /// + /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc + (T), Rc, Rc::new +} #[cfg(any(feature = "std", feature = "alloc"))] impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T> @@ -1456,7 +1478,11 @@ where #[cfg(all(feature = "unstable", feature = "rc", any(feature = "std", feature = "alloc")))] macro_rules! box_forwarded_impl { - ($t:ident) => { + ( + $(#[doc = $doc:tt])* + $t:ident + ) => { + $(#[doc = $doc])* impl<'de, T: ?Sized> Deserialize<'de> for $t where Box: Deserialize<'de>, @@ -1472,10 +1498,28 @@ macro_rules! box_forwarded_impl { } #[cfg(all(feature = "unstable", feature = "rc", any(feature = "std", feature = "alloc")))] -box_forwarded_impl!(Rc); +box_forwarded_impl! { + /// This impl requires the [`"rc"`] Cargo feature of Serde. + /// + /// Deserializing a data structure containing `Rc` will not attempt to + /// deduplicate `Rc` references to the same data. Every deserialized `Rc` + /// will end up with a strong count of 1. + /// + /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc + Rc +} #[cfg(all(feature = "unstable", feature = "rc", any(feature = "std", feature = "alloc")))] -box_forwarded_impl!(Arc); +box_forwarded_impl! { + /// This impl requires the [`"rc"`] Cargo feature of Serde. + /// + /// Deserializing a data structure containing `Arc` will not attempt to + /// deduplicate `Arc` references to the same data. Every deserialized `Arc` + /// will end up with a strong count of 1. + /// + /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc + Arc +} //////////////////////////////////////////////////////////////////////////////// diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index fc6d99a0..225bdcc4 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -320,8 +320,12 @@ map_impl!(HashMap); //////////////////////////////////////////////////////////////////////////////// macro_rules! deref_impl { - ($($desc:tt)+) => { - impl $($desc)+ { + ( + $(#[doc = $doc:tt])* + <$($desc:tt)+ + ) => { + $(#[doc = $doc])* + impl <$($desc)+ { #[inline] fn serialize(&self, serializer: S) -> Result where @@ -340,10 +344,30 @@ deref_impl!(<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize); deref_impl!( Serialize for Box where T: Serialize); #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] -deref_impl!( Serialize for Rc where T: Serialize); +deref_impl! { + /// This impl requires the [`"rc"`] Cargo feature of Serde. + /// + /// Serializing a data structure containing `Rc` will serialize a copy of + /// the contents of the `Rc` each time the `Rc` is referenced within the + /// data structure. Serialization will not attempt to deduplicate these + /// repeated data. + /// + /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc + Serialize for Rc where T: Serialize +} #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] -deref_impl!( Serialize for Arc where T: Serialize); +deref_impl! { + /// This impl requires the [`"rc"`] Cargo feature of Serde. + /// + /// Serializing a data structure containing `Arc` will serialize a copy of + /// the contents of the `Arc` each time the `Arc` is referenced within the + /// data structure. Serialization will not attempt to deduplicate these + /// repeated data. + /// + /// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc + Serialize for Arc where T: Serialize +} #[cfg(any(feature = "std", feature = "alloc"))] deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned);