#[repr(transparent)]pub struct RcRecursive<T>(pub Rc<RefCell<Option<T>>>);Expand description
The parent (origin) anchor definition that may have recursive references to it.
This type provides the value for the references and must be placed where the original value is defined.
Fields that reference this value (possibly recursively) must be wrapped in RcRecursion.
use std::cell::Ref;
use serde::Deserialize;
use serde_saphyr::{RcRecursion, RcRecursive};
#[derive(Deserialize)]
struct King {
name: String,
coronator: RcRecursion<King>, // who crowned this king
}
#[derive(Deserialize)]
struct Kingdom {
king: RcRecursive<King>,
}
let yaml = r#"
king: &root
name: "Aurelian I"
coronator: *root # this king crowned himself
"#;
let kingdom_data: Kingdom = serde_saphyr::from_str(yaml).unwrap();
let king: Ref<King> = kingdom_data.king.borrow();
let coronator = king
.coronator
.upgrade().expect("coronator always exists");
let coronator_name = &coronator.borrow().name;
assert_eq!(coronator_name, "Aurelian I");Tuple Fields§
§0: Rc<RefCell<Option<T>>>Implementations§
Source§impl<T> RcRecursive<T>
impl<T> RcRecursive<T>
Sourcepub fn try_borrow_initialized(&self) -> Option<Ref<'_, T>>
pub fn try_borrow_initialized(&self) -> Option<Ref<'_, T>>
Try to borrow the inner value if the recursive placeholder has been initialized.
Returns None while a recursive anchor is still being deserialized.
Sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Borrow the inner value.
§Panics
Panics if called while a recursive anchor placeholder is still uninitialized.
Use try_borrow_initialized when early access is possible.
Trait Implementations§
Source§impl<T: Clone> Clone for RcRecursive<T>
impl<T: Clone> Clone for RcRecursive<T>
Source§fn clone(&self) -> RcRecursive<T>
fn clone(&self) -> RcRecursive<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 RcRecursive<T>
impl<T> Debug for RcRecursive<T>
Source§impl<T: Default> Default for RcRecursive<T>
impl<T: Default> Default for RcRecursive<T>
Source§impl<T> Deref for RcRecursive<T>
impl<T> Deref for RcRecursive<T>
Source§impl<'de, T> Deserialize<'de> for RcRecursive<T>where
T: Deserialize<'de> + 'static,
Available on crate feature deserialize only.
impl<'de, T> Deserialize<'de> for RcRecursive<T>where
T: Deserialize<'de> + 'static,
Available on crate feature
deserialize only.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
impl<T> Eq for RcRecursive<T>
Source§impl<T> From<&RcRecursive<T>> for RcRecursion<T>
impl<T> From<&RcRecursive<T>> for RcRecursion<T>
Source§fn from(rca: &RcRecursive<T>) -> Self
fn from(rca: &RcRecursive<T>) -> Self
Converts to this type from the input type.
Source§impl<T> PartialEq for RcRecursive<T>
impl<T> PartialEq for RcRecursive<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for RcRecursive<T>
impl<T> !Send for RcRecursive<T>
impl<T> !Sync for RcRecursive<T>
impl<T> !UnwindSafe for RcRecursive<T>
impl<T> Freeze for RcRecursive<T>
impl<T> Unpin for RcRecursive<T>
impl<T> UnsafeUnpin for RcRecursive<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