Skip to main content

Map

Struct Map 

Source
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>

Source

pub fn new(replica: ReplicaId) -> Self

Create an empty map for the given replica.

Source

pub fn new_random() -> Self

Create a new instance with a random ReplicaId from OS entropy. See crate::new_replica_id.

Source

pub fn replica_id(&self) -> ReplicaId

This replica’s id.

Source

pub fn len(&self) -> usize

Number of visible (non-tombstoned) entries.

Source

pub fn is_empty(&self) -> bool

Are there any visible entries?

Source

pub fn get(&self, key: &K) -> Option<&V>

Look up the value for key, or None if absent / tombstoned.

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)> + '_

Iterate visible (key, value) pairs.

Source

pub fn keys(&self) -> impl Iterator<Item = &K> + '_

Iterate visible keys.

Source

pub fn values(&self) -> impl Iterator<Item = &V> + '_

Iterate visible values.

Source

pub fn contains_key(&self, key: &K) -> bool

Does the map contain key?

Source

pub fn set(&mut self, key: K, value: V) -> MapOp<K, V>

Set key to value. Returns the generated MapOp.

Source

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.

Source

pub fn apply(&mut self, op: MapOp<K, V>) -> Result<(), Error>

Apply a remote operation. Idempotent.

Source

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.

Source

pub fn ops(&self) -> &[MapOp<K, V>]

All ops observed by this replica, in observation order.

Source

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.

Source

pub fn version(&self) -> &VersionVector

This replica’s current version vector.

Trait Implementations§

Source§

impl<K: Clone + Eq + Hash + Clone, V: Clone + Clone> Clone for Map<K, V>

Source§

fn clone(&self) -> Map<K, V>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug + Eq + Hash + Clone, V: Debug + Clone> Debug for Map<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: Eq + Hash + Clone, V: Clone> Default for Map<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, K, V> Deserialize<'de> for Map<K, V>
where K: Eq + Hash + Clone + Deserialize<'de>, V: Clone + Deserialize<'de>,

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, V> Serialize for Map<K, V>
where K: Eq + Hash + Clone + Serialize, V: Clone + Serialize,

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for Map<K, V>

§

impl<K, V> RefUnwindSafe for Map<K, V>

§

impl<K, V> Send for Map<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for Map<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Map<K, V>
where K: Unpin, V: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,