mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 17:11:02 +00:00
+50
-6
@@ -470,7 +470,11 @@ impl<'de> Deserialize<'de> for CString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! forwarded_impl {
|
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 {
|
impl<'de $(, $id : Deserialize<'de>,)*> Deserialize<'de> for $ty {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -1432,10 +1436,28 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice);
|
|||||||
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
||||||
|
|
||||||
#[cfg(all(not(feature = "unstable"), feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(all(not(feature = "unstable"), feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
forwarded_impl!((T), Arc<T>, 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<T>, Arc::new
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(not(feature = "unstable"), feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(all(not(feature = "unstable"), feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
forwarded_impl!((T), Rc<T>, 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<T>, Rc::new
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
|
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")))]
|
#[cfg(all(feature = "unstable", feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
macro_rules! box_forwarded_impl {
|
macro_rules! box_forwarded_impl {
|
||||||
($t:ident) => {
|
(
|
||||||
|
$(#[doc = $doc:tt])*
|
||||||
|
$t:ident
|
||||||
|
) => {
|
||||||
|
$(#[doc = $doc])*
|
||||||
impl<'de, T: ?Sized> Deserialize<'de> for $t<T>
|
impl<'de, T: ?Sized> Deserialize<'de> for $t<T>
|
||||||
where
|
where
|
||||||
Box<T>: Deserialize<'de>,
|
Box<T>: Deserialize<'de>,
|
||||||
@@ -1472,10 +1498,28 @@ macro_rules! box_forwarded_impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[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")))]
|
#[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
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
+28
-4
@@ -320,8 +320,12 @@ map_impl!(HashMap<K: Eq + Hash, V, H: BuildHasher>);
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! deref_impl {
|
macro_rules! deref_impl {
|
||||||
($($desc:tt)+) => {
|
(
|
||||||
impl $($desc)+ {
|
$(#[doc = $doc:tt])*
|
||||||
|
<$($desc:tt)+
|
||||||
|
) => {
|
||||||
|
$(#[doc = $doc])*
|
||||||
|
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
|
||||||
@@ -340,10 +344,30 @@ deref_impl!(<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize);
|
|||||||
deref_impl!(<T: ?Sized> Serialize for Box<T> where T: Serialize);
|
deref_impl!(<T: ?Sized> Serialize for Box<T> where T: Serialize);
|
||||||
|
|
||||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
deref_impl!(<T: ?Sized> Serialize for Rc<T> 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
|
||||||
|
<T: ?Sized> Serialize for Rc<T> where T: Serialize
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
deref_impl!(<T: ?Sized> Serialize for Arc<T> 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
|
||||||
|
<T: ?Sized> Serialize for Arc<T> where T: Serialize
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned);
|
deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned);
|
||||||
|
|||||||
Reference in New Issue
Block a user