pub struct Hook<S> { /* private fields */ }
Expand description
A descriptor used to reference to shared collections by their unique logical identifiers, which can be either Root-level collections or shared collections Nested into each other. It can be resolved from any shared reference using SharedRef::hook.
Implementations§
source§impl<S: SharedRef> Hook<S>
impl<S: SharedRef> Hook<S>
sourcepub fn get<T: ReadTxn>(&self, txn: &T) -> Option<S>
pub fn get<T: ReadTxn>(&self, txn: &T) -> Option<S>
Returns a reference to a shared collection current hook points to, if it exists and (in case of nested collections) has not been deleted.
§Example
use yrs::{Hook, Doc, Map, MapRef, Nested, SharedRef, TextPrelim, TextRef, Transact, WriteTxn};
let doc = Doc::new();
let mut txn = doc.transact_mut();
let root = txn.get_or_insert_map("root"); // root-level collection
let nested = root.insert(&mut txn, "nested", TextPrelim::new("")); // nested collection
let root_hook: Hook<MapRef> = root.hook();
let nested_hook: Hook<TextRef> = nested.hook();
// hook can be used to retrieve collection reference as long as its alive
assert_eq!(nested_hook.get(&txn), Some(nested));
// after nested collection is deleted it can no longer be referenced
root.remove(&mut txn, "nested");
assert_eq!(nested_hook.get(&txn), None, "wtf");
// descriptors work also for root types
assert_eq!(root_hook.get(&txn), Some(root));
Trait Implementations§
source§impl<'de, S> Deserialize<'de> for Hook<S>
impl<'de, S> Deserialize<'de> for Hook<S>
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<S> PartialEq for Hook<S>
impl<S> PartialEq for Hook<S>
impl<S> Eq for Hook<S>
Auto Trait Implementations§
impl<S> Freeze for Hook<S>
impl<S> RefUnwindSafe for Hook<S>where
S: RefUnwindSafe,
impl<S> Send for Hook<S>where
S: Send,
impl<S> Sync for Hook<S>where
S: Sync,
impl<S> Unpin for Hook<S>where
S: Unpin,
impl<S> UnwindSafe for Hook<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