diff --git a/src/value.rs b/src/value.rs index c15ccb848..a1a88c17b 100644 --- a/src/value.rs +++ b/src/value.rs @@ -855,6 +855,32 @@ where } } +#[cfg(feature = "serde")] +impl serde::Serialize for Owned +where + T: serde::Serialize, +{ + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.map_ref(|this| this.serialize(serializer)) + } +} + +#[cfg(feature = "serde")] +impl<'de, T> serde::Deserialize<'de> for Owned +where + T: serde::Deserialize<'de>, +{ + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + T::deserialize(deserializer).map(Self::new) + } +} + /// A read-only reference to the value in an [`Owned`]. pub struct OwnedRef<'a, T>(Ref<'a, GenerationalValue>) where @@ -1277,6 +1303,32 @@ impl Dynamic { } } +#[cfg(feature = "serde")] +impl serde::Serialize for Dynamic +where + T: serde::Serialize, +{ + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.map_ref(|this| this.serialize(serializer)) + } +} + +#[cfg(feature = "serde")] +impl<'de, T> serde::Deserialize<'de> for Dynamic +where + T: serde::Deserialize<'de>, +{ + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + T::deserialize(deserializer).map(Self::new) + } +} + /// An error returned from [`Dynamic::try_compare_swap`]. #[derive(Debug, Clone, Eq, PartialEq)] pub enum TryCompareSwapError {