pub struct Map<K: Eq + Hash + Clone, V: Clone> { /* private fields */ }Expand description
LWW-Map CRDT. See the module docs for semantics.
Implementations§
Source§impl<K: Eq + Hash + Clone, V: Clone> Map<K, V>
impl<K: Eq + Hash + Clone, V: Clone> Map<K, V>
Sourcepub fn new_random() -> Self
pub fn new_random() -> Self
Create a new instance with a random ReplicaId from OS entropy.
See crate::new_replica_id.
Sourcepub fn replica_id(&self) -> ReplicaId
pub fn replica_id(&self) -> ReplicaId
This replica’s id.
Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Look up the value for key, or None if absent / tombstoned.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Does the map contain key?
Sourcepub fn set(&mut self, key: K, value: V) -> MapOp<K, V>
pub fn set(&mut self, key: K, value: V) -> MapOp<K, V>
Set key to value. Returns the generated MapOp.
Sourcepub fn remove(&mut self, key: K) -> MapOp<K, V>
pub fn remove(&mut self, key: K) -> MapOp<K, V>
Remove key. Always emits an op (even if the key was absent), so the
remove can be replicated.
Sourcepub fn apply(&mut self, op: MapOp<K, V>) -> Result<(), Error>
pub fn apply(&mut self, op: MapOp<K, V>) -> Result<(), Error>
Apply a remote operation. Idempotent.
Sourcepub fn merge(&mut self, other: &Self)
pub fn merge(&mut self, other: &Self)
Merge all of other’s state into self. Equivalent to applying
every op in other.log that we haven’t seen, in OpId order.
Sourcepub fn ops_since<'a>(
&'a self,
since: &'a VersionVector,
) -> impl Iterator<Item = &'a MapOp<K, V>> + 'a
pub fn ops_since<'a>( &'a self, since: &'a VersionVector, ) -> impl Iterator<Item = &'a MapOp<K, V>> + 'a
Iterate over ops not yet seen by since.
Sourcepub fn version(&self) -> &VersionVector
pub fn version(&self) -> &VersionVector
This replica’s current version vector.
Trait Implementations§
Source§impl<'de, K, V> Deserialize<'de> for Map<K, V>
Available on crate feature serde only.
impl<'de, K, V> Deserialize<'de> for Map<K, V>
Available on crate feature
serde only.Source§fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<K, V> Freeze for Map<K, V>
impl<K, V> RefUnwindSafe for Map<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for Map<K, V>
impl<K, V> Sync for Map<K, V>
impl<K, V> Unpin for Map<K, V>
impl<K, V> UnsafeUnpin for Map<K, V>
impl<K, V> UnwindSafe for Map<K, V>where
K: UnwindSafe,
V: 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