diff --git a/src/unique_arc.rs b/src/unique_arc.rs index 5afdd6c..14e2b8a 100644 --- a/src/unique_arc.rs +++ b/src/unique_arc.rs @@ -8,6 +8,9 @@ use core::ops::{Deref, DerefMut}; use core::ptr::{self, addr_of_mut, NonNull}; use core::sync::atomic::AtomicUsize; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + use crate::iterator_as_exact_size_iterator::IteratorAsExactSizeIterator; use crate::HeaderSlice; @@ -274,6 +277,26 @@ unsafe impl unsize::CoerciblePtr for UniqueArc { } } +#[cfg(feature = "serde")] +impl<'de, T: Deserialize<'de>> Deserialize<'de> for UniqueArc { + fn deserialize(deserializer: D) -> Result, D::Error> + where + D: ::serde::de::Deserializer<'de>, + { + T::deserialize(deserializer).map(UniqueArc::new) + } +} + +#[cfg(feature = "serde")] +impl Serialize for UniqueArc { + fn serialize(&self, serializer: S) -> Result + where + S: ::serde::ser::Serializer, + { + (**self).serialize(serializer) + } +} + #[cfg(test)] mod tests { use crate::{Arc, HeaderSliceWithLength, HeaderWithLength, UniqueArc};