Struct Hook
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§
§impl<S> Hook<S>where
S: SharedRef,
impl<S> Hook<S>where
S: SharedRef,
pub fn get<T>(&self, txn: &T) -> Option<S>where
T: ReadTxn,
pub fn get<T>(&self, txn: &T) -> Option<S>where
T: ReadTxn,
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));pub fn into_nested(self) -> Option<Nested<S>>
pub fn into_nested(self) -> Option<Nested<S>>
Trait Implementations§
§impl<'de, S> Deserialize<'de> for Hook<S>
impl<'de, S> Deserialize<'de> for Hook<S>
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Hook<S>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Hook<S>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl<S> Serialize for Hook<S>
impl<S> Serialize for Hook<S>
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more