[−][src]Struct crdts::map::Map
Map CRDT - Supports Composition of CRDT's with reset-remove semantics.
Reset-remove means that if one replica removes an entry while another actor concurrently edits that entry, once we sync these two maps, we will see that the entry is still in the map but all edits seen by the removing actor will be gone.
See examples/reset_remove.rs for an example of reset-remove semantics in action.
Implementations
impl<K: Ord, V: Val<A> + Default, A: Actor> Map<K, V, A>
[src]
pub fn new() -> Self
[src]
Constructs an empty Map
pub fn is_empty(&self) -> ReadCtx<bool, A>
[src]
Returns true if the map has no entries, false otherwise
pub fn len(&self) -> ReadCtx<usize, A>
[src]
Returns the number of entries in the Map
pub fn get(&self, key: &K) -> ReadCtx<Option<V>, A>
[src]
Retrieve value stored under a key
pub fn update<F>(&self, key: impl Into<K>, ctx: AddCtx<A>, f: F) -> Op<K, V, A> where
F: FnOnce(&V, AddCtx<A>) -> V::Op,
[src]
F: FnOnce(&V, AddCtx<A>) -> V::Op,
Update a value under some key.
If the key is not present in the map, the updater will be given the
result of V::default()
. The default
value is used to ensure
eventual consistency since our Map
's values are CRDTs themselves.
The impl Into<K>
bound provides a nice way of providing an input key that
can easily convert to the Map
's key. For example, we can call this function
with "hello": &str
and it can be converted to String
.
pub fn rm(&self, key: impl Into<K>, ctx: RmCtx<A>) -> Op<K, V, A>
[src]
Remove an entry from the Map
The impl Into<K>
bound provides a nice way of providing an input key that
can easily convert to the Map
's key. For example, we can call this function
with "hello": &str
and it can be converted to String
.
pub fn read_ctx(&self) -> ReadCtx<(), A>
[src]
Retrieve the current read context
pub fn keys(&self) -> impl Iterator<Item = ReadCtx<&K, A>>
[src]
Gets an iterator over the keys of the Map
.
Examples
use crdts::Map; use crdts::MVReg; use crdts::CmRDT; type Actor = &'static str; type Key = &'static str; let actor = "actor"; let mut map: Map<i32, MVReg<Key, Actor>, Actor> = Map::new(); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(100, add_ctx, |v, a| v.write("foo", a))); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(50, add_ctx, |v, a| v.write("bar", a))); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(200, add_ctx, |v, a| v.write("baz", a))); let mut keys: Vec<_> = map.keys().map(|key_ctx| *key_ctx.val).collect(); keys.sort(); assert_eq!(keys, &[50, 100, 200]);
pub fn values(&self) -> impl Iterator<Item = ReadCtx<&V, A>>
[src]
Gets an iterator over the values of the Map
.
Examples
use crdts::Map; use crdts::MVReg; use crdts::CmRDT; type Actor = &'static str; type Key = &'static str; let actor = "actor"; let mut map: Map<i32, MVReg<Key, Actor>, Actor> = Map::new(); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(100, add_ctx, |v, a| v.write("foo", a))); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(50, add_ctx, |v, a| v.write("bar", a))); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(200, add_ctx, |v, a| v.write("baz", a))); let mut values: Vec<_> = map .values() .map(|val_ctx| val_ctx.val.read().val[0]) .collect(); values.sort(); assert_eq!(values, &["bar", "baz", "foo"]);
pub fn iter(&self) -> impl Iterator<Item = ReadCtx<(&K, &V), A>>
[src]
Gets an iterator over the entries of the Map
.
Examples
use crdts::Map; use crdts::MVReg; use crdts::CmRDT; type Actor = &'static str; type Key = &'static str; let actor = "actor"; let mut map: Map<i32, MVReg<Key, Actor>, Actor> = Map::new(); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(100, add_ctx, |v, a| v.write("foo", a))); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(50, add_ctx, |v, a| v.write("bar", a))); let add_ctx = map.read_ctx().derive_add_ctx(actor); map.apply(map.update(200, add_ctx, |v, a| v.write("baz", a))); let mut items: Vec<_> = map .iter() .map(|item_ctx| (*item_ctx.val.0, item_ctx.val.1.read().val[0])) .collect(); items.sort(); assert_eq!(items, &[(50, "bar"), (100, "foo"), (200, "baz")]);
Trait Implementations
impl<K: Ord, V: Val<A> + Default, A: Actor> Causal<A> for Map<K, V, A>
[src]
impl<K: Clone + Ord, V: Clone + Val<A>, A: Clone + Actor> Clone for Map<K, V, A>
[src]
impl<K: Ord, V: Val<A> + Default, A: Actor> CmRDT for Map<K, V, A>
[src]
type Op = Op<K, V, A>
Op defines a mutation to the CRDT. As long as Op's from one actor are replayed in exactly the same order they were generated by that actor, the CRDT will converge. In other words, we must have a total ordering on each actors operations, while requiring only a partial order over all ops. E.g. Read more
pub fn apply(&mut self, op: Self::Op)
[src]
impl<K: Ord, V: Val<A> + Default, A: Actor> CvRDT for Map<K, V, A>
[src]
impl<K: Debug + Ord, V: Debug + Val<A>, A: Debug + Actor> Debug for Map<K, V, A>
[src]
impl<K: Ord, V: Val<A> + Default, A: Actor> Default for Map<K, V, A>
[src]
impl<'de, K: Ord, V: Val<A>, A: Actor> Deserialize<'de> for Map<K, V, A> where
K: Deserialize<'de>,
V: Deserialize<'de>,
A: Deserialize<'de>,
[src]
K: Deserialize<'de>,
V: Deserialize<'de>,
A: Deserialize<'de>,
pub fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<K: Eq + Ord, V: Eq + Val<A>, A: Eq + Actor> Eq for Map<K, V, A>
[src]
impl<K: PartialEq + Ord, V: PartialEq + Val<A>, A: PartialEq + Actor> PartialEq<Map<K, V, A>> for Map<K, V, A>
[src]
pub fn eq(&self, other: &Map<K, V, A>) -> bool
[src]
pub fn ne(&self, other: &Map<K, V, A>) -> bool
[src]
impl<K: Ord, V: Val<A>, A: Actor> Serialize for Map<K, V, A> where
K: Serialize,
V: Serialize,
A: Serialize,
[src]
K: Serialize,
V: Serialize,
A: Serialize,
pub fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<K: Ord, V: Val<A>, A: Actor> StructuralEq for Map<K, V, A>
[src]
impl<K: Ord, V: Val<A>, A: Actor> StructuralPartialEq for Map<K, V, A>
[src]
Auto Trait Implementations
impl<K, V, A> RefUnwindSafe for Map<K, V, A> where
A: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
A: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, A> Send for Map<K, V, A> where
A: Send,
K: Send,
V: Send,
A: Send,
K: Send,
V: Send,
impl<K, V, A> Sync for Map<K, V, A> where
A: Sync,
K: Sync,
V: Sync,
A: Sync,
K: Sync,
V: Sync,
impl<K, V, A> Unpin for Map<K, V, A>
impl<K, V, A> UnwindSafe for Map<K, V, A> where
A: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
A: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<A, T> Val<A> for T where
A: Actor,
T: Clone + Causal<A> + CmRDT + CvRDT,
[src]
A: Actor,
T: Clone + Causal<A> + CmRDT + CvRDT,