#[repr(transparent)]pub struct RcWeakAnchor<T>(pub Weak<T>);Expand description
A wrapper around std::rc::Weak<T> that opts into 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-nullis resolved through the YAML anchor context; it is rejected when no matching strong anchor is available.
§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> Clone for RcWeakAnchor<T>
impl<T: Clone> 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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for RcWeakAnchor<T>
impl<T> Debug for RcWeakAnchor<T>
impl<T> Eq for RcWeakAnchor<T>
Source§impl<T> From<&Rc<T>> for RcWeakAnchor<T>
impl<T> From<&Rc<T>> for RcWeakAnchor<T>
Source§impl<T> From<&RcAnchor<T>> for RcWeakAnchor<T>
impl<T> From<&RcAnchor<T>> for RcWeakAnchor<T>
Source§impl<T> PartialEq for RcWeakAnchor<T>
impl<T> PartialEq for RcWeakAnchor<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for RcWeakAnchor<T>
impl<T> !Send for RcWeakAnchor<T>
impl<T> !Sync for RcWeakAnchor<T>
impl<T> !UnwindSafe for RcWeakAnchor<T>
impl<T> Freeze for RcWeakAnchor<T>
impl<T> Unpin for RcWeakAnchor<T>
impl<T> UnsafeUnpin for RcWeakAnchor<T>where
Weak<T>: UnsafeUnpin,
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