#[repr(transparent)]pub struct Root<S> {
pub name: Arc<str>,
/* private fields */
}Expand description
A logical reference to a root-level shared collection. It can be shared across different documents to reference the same logical type.
§Example
use yrs::{Doc, RootRef, SharedRef, TextRef, Transact};
let root = TextRef::root("hello");
let doc1 = Doc::new();
let txt1 = root.get_or_create(&mut doc1.transact_mut());
let doc2 = Doc::new();
let txt2 = root.get_or_create(&mut doc2.transact_mut());
// instances of TextRef point to different heap objects
assert_ne!(&txt1 as *const _, &txt2 as *const _);
// logical descriptors of both TextRef are the same as they refer to the
// same logical entity
assert_eq!(txt1.hook(), txt2.hook());Fields§
§name: Arc<str>Unique identifier of root-level shared collection.
Implementations§
Source§impl<S: RootRef> Root<S>
impl<S: RootRef> Root<S>
Sourcepub fn new<N: Into<Arc<str>>>(name: N) -> Self
pub fn new<N: Into<Arc<str>>>(name: N) -> Self
Creates a new logical reference for a root-level shared collection of a given name and type. Returned value can be used to resolve instances of root-level types by calling Root::get or Root::get_or_create.
Sourcepub fn get_or_create<T: WriteTxn>(&self, txn: &mut T) -> S
pub fn get_or_create<T: WriteTxn>(&self, txn: &mut T) -> S
Returns a reference to a shared root-level collection current Root represents, or creates it if it wasn’t instantiated before.
Trait Implementations§
impl<S: Eq> Eq for Root<S>
Source§impl<S: Ord> Ord for Root<S>
impl<S: Ord> Ord for Root<S>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<S: PartialOrd> PartialOrd for Root<S>
impl<S: PartialOrd> PartialOrd for Root<S>
impl<S: PartialEq> StructuralPartialEq for Root<S>
Auto Trait Implementations§
impl<S> Freeze for Root<S>
impl<S> RefUnwindSafe for Root<S>where
S: RefUnwindSafe,
impl<S> Send for Root<S>where
S: Send,
impl<S> Sync for Root<S>where
S: Sync,
impl<S> Unpin for Root<S>where
S: Unpin,
impl<S> UnsafeUnpin for Root<S>
impl<S> UnwindSafe for Root<S>where
S: UnwindSafe,
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