Add impls for Weak
This commit is contained in:
parent
dc921892be
commit
0bc9c729b3
@ -1474,6 +1474,44 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This impl requires the [`"rc"`] Cargo feature of Serde. The resulting
|
||||||
|
/// `Weak<T>` has a reference count of 0 and cannot be upgraded.
|
||||||
|
///
|
||||||
|
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||||
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
|
impl<'de, T: ?Sized> Deserialize<'de> for RcWeak<T>
|
||||||
|
where
|
||||||
|
T: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
try!(Option::<T>::deserialize(deserializer));
|
||||||
|
Ok(RcWeak::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This impl requires the [`"rc"`] Cargo feature of Serde. The resulting
|
||||||
|
/// `Weak<T>` has a reference count of 0 and cannot be upgraded.
|
||||||
|
///
|
||||||
|
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||||
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
|
impl<'de, T: ?Sized> Deserialize<'de> for ArcWeak<T>
|
||||||
|
where
|
||||||
|
T: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
try!(Option::<T>::deserialize(deserializer));
|
||||||
|
Ok(ArcWeak::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[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 {
|
||||||
(
|
(
|
||||||
|
@ -179,14 +179,14 @@ mod lib {
|
|||||||
pub use std::boxed::Box;
|
pub use std::boxed::Box;
|
||||||
|
|
||||||
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
|
||||||
pub use alloc::rc::Rc;
|
pub use alloc::rc::{Rc, Weak as RcWeak};
|
||||||
#[cfg(all(feature = "rc", feature = "std"))]
|
#[cfg(all(feature = "rc", feature = "std"))]
|
||||||
pub use std::rc::Rc;
|
pub use std::rc::{Rc, Weak as RcWeak};
|
||||||
|
|
||||||
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
|
||||||
pub use alloc::arc::Arc;
|
pub use alloc::arc::{Arc, Weak as ArcWeak};
|
||||||
#[cfg(all(feature = "rc", feature = "std"))]
|
#[cfg(all(feature = "rc", feature = "std"))]
|
||||||
pub use std::sync::Arc;
|
pub use std::sync::{Arc, Weak as ArcWeak};
|
||||||
|
|
||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
pub use alloc::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
pub use alloc::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
||||||
|
@ -374,6 +374,40 @@ deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwne
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
|
///
|
||||||
|
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||||
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
|
impl<T: ?Sized> Serialize for RcWeak<T>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
self.upgrade().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
|
///
|
||||||
|
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
|
||||||
|
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
|
||||||
|
impl<T: ?Sized> Serialize for ArcWeak<T>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
self.upgrade().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
impl<T> Serialize for NonZero<T>
|
impl<T> Serialize for NonZero<T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user