#[repr(transparent)]pub struct Map(_);Expand description
Collection used to store key-value entries in an unordered manner. Keys are always represented as UTF-8 strings. Values can be any value type supported by Yrs: JSON-like primitives as well as shared data types.
In terms of conflict resolution, Map uses logical last-write-wins principle, meaning the past updates are automatically overridden and discarded by newer ones, while concurrent updates made by different peers are resolved into a single value using document id seniority to establish order.
Implementations
sourceimpl Map
impl Map
sourcepub fn to_json(&self) -> Any
pub fn to_json(&self) -> Any
Converts all entries of a current map into JSON-like object representation.
sourcepub fn keys(&self) -> Keys<'_>ⓘNotable traits for Keys<'a>impl<'a> Iterator for Keys<'a> type Item = &'a str;
pub fn keys(&self) -> Keys<'_>ⓘNotable traits for Keys<'a>impl<'a> Iterator for Keys<'a> type Item = &'a str;
Returns an iterator that enables to traverse over all keys of entries stored within current map. These keys are not ordered.
sourcepub fn values(&self) -> Values<'_>ⓘNotable traits for Values<'a>impl<'a> Iterator for Values<'a> type Item = Vec<Value>;
pub fn values(&self) -> Values<'_>ⓘNotable traits for Values<'a>impl<'a> Iterator for Values<'a> type Item = Vec<Value>;
Returns an iterator that enables to traverse over all values stored within current map.
sourcepub fn iter(&self) -> MapIter<'_>ⓘNotable traits for MapIter<'a>impl<'a> Iterator for MapIter<'a> type Item = (&'a str, Value);
pub fn iter(&self) -> MapIter<'_>ⓘNotable traits for MapIter<'a>impl<'a> Iterator for MapIter<'a> type Item = (&'a str, Value);
Returns an iterator that enables to traverse over all entries - tuple of key-value pairs - stored within current map.
sourcepub fn insert<K: Into<Rc<str>>, V: Prelim>(
&self,
txn: &mut Transaction,
key: K,
value: V
) -> Option<Value>
pub fn insert<K: Into<Rc<str>>, V: Prelim>(
&self,
txn: &mut Transaction,
key: K,
value: V
) -> Option<Value>
Inserts a new value under given key into current map. Returns a value stored previously
under the same key (if any existed).
sourcepub fn remove(&self, txn: &mut Transaction, key: &str) -> Option<Value>
pub fn remove(&self, txn: &mut Transaction, key: &str) -> Option<Value>
Removes a stored within current map under a given key. Returns that value or None if
no entry with a given key was present in current map.
sourcepub fn get(&self, key: &str) -> Option<Value>
pub fn get(&self, key: &str) -> Option<Value>
Returns a value stored under a given key within current map, or None if no entry
with such key existed.
sourcepub fn contains(&self, key: &str) -> bool
pub fn contains(&self, key: &str) -> bool
Checks if an entry with given key can be found within current map.
sourcepub fn clear(&self, txn: &mut Transaction)
pub fn clear(&self, txn: &mut Transaction)
Clears the contents of current map, effectively removing all of its entries.
sourcepub fn observe<F>(&mut self, f: F) -> Subscription<MapEvent> where
F: Fn(&Transaction, &MapEvent) + 'static,
pub fn observe<F>(&mut self, f: F) -> Subscription<MapEvent> where
F: Fn(&Transaction, &MapEvent) + 'static,
Subscribes a given callback to be triggered whenever current map is changed. A callback is triggered whenever a transaction gets committed. This function does not trigger if changes have been observed by nested shared collections.
All map changes can be tracked by using [Event::keys] method.
Returns an [Observer] which, when dropped, will unsubscribe current callback.
sourcepub fn unobserve(&mut self, subscription_id: SubscriptionId)
pub fn unobserve(&mut self, subscription_id: SubscriptionId)
Unsubscribes a previously subscribed event callback identified by given subscription_id.
Trait Implementations
impl Eq for Map
impl StructuralEq for Map
impl StructuralPartialEq for Map
Auto Trait Implementations
impl !RefUnwindSafe for Map
impl !Send for Map
impl !Sync for Map
impl Unpin for Map
impl !UnwindSafe for Map
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> DeepObservable for T where
T: AsMut<Branch>,
impl<T> DeepObservable for T where
T: AsMut<Branch>,
sourcefn observe_deep<F>(&mut self, f: F) -> Subscription<Events> where
F: 'static + Fn(&Transaction, &Events),
fn observe_deep<F>(&mut self, f: F) -> Subscription<Events> where
F: 'static + Fn(&Transaction, &Events),
sourcefn unobserve_deep(&mut self, subscription_id: u32)
fn unobserve_deep(&mut self, subscription_id: u32)
Unobserves callback identified by subscription_id (which can be obtained by consuming
Subscription using into cast). Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more