#[repr(transparent)]pub struct RcWeakAnchor<T: ?Sized>(pub Weak<T>);Expand description
Serialization public API is defined at crate root
A wrapper around [Weak<T>] (from std::rc) that opt-ins for anchor emission.
When serialized, if the weak reference is dangling (i.e., the value was dropped),
it emits null to indicate that the target no longer exists.
Provides convenience methods like upgrade and is_dangling.
Note on deserialization:
nulldeserializes back into a dangling weak (Weak::new()). Non-nullcannot be safely reconstructed into aWeakwithout a shared registry; we reject it. Ask if you want an ID/registry-based scheme to restore sharing.
§Examples
use std::rc::Rc;
use serde_saphyr::{RcAnchor, RcWeakAnchor};
let rc_anchor = RcAnchor::from(Rc::new(String::from("Persistent")));
// Create a weak anchor from a strong reference
let weak_anchor = RcWeakAnchor::from(&rc_anchor.0);
assert!(weak_anchor.upgrade().is_some());
drop(rc_anchor);
assert!(weak_anchor.upgrade().is_none());Tuple Fields§
§0: Weak<T>Implementations§
Trait Implementations§
Source§impl<T: Clone + ?Sized> Clone for RcWeakAnchor<T>
impl<T: Clone + ?Sized> Clone for RcWeakAnchor<T>
Source§fn clone(&self) -> RcWeakAnchor<T>
fn clone(&self) -> RcWeakAnchor<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: ?Sized> Debug for RcWeakAnchor<T>
impl<T: ?Sized> Debug for RcWeakAnchor<T>
Source§impl<'de, T> Deserialize<'de> for RcWeakAnchor<T>where
T: Deserialize<'de> + 'static,
impl<'de, T> Deserialize<'de> for RcWeakAnchor<T>where
T: Deserialize<'de> + 'static,
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: ?Sized> PartialEq for RcWeakAnchor<T>
impl<T: ?Sized> PartialEq for RcWeakAnchor<T>
Source§impl<T: Serialize> Serialize for RcWeakAnchor<T>
impl<T: Serialize> Serialize for RcWeakAnchor<T>
impl<T: ?Sized> Eq for RcWeakAnchor<T>
Auto Trait Implementations§
impl<T> Freeze for RcWeakAnchor<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for RcWeakAnchor<T>
impl<T> !Send for RcWeakAnchor<T>
impl<T> !Sync for RcWeakAnchor<T>
impl<T> Unpin for RcWeakAnchor<T>where
T: ?Sized,
impl<T> !UnwindSafe for RcWeakAnchor<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more