[−][src]Struct crdts::lwwreg::LWWReg
LWWReg
is a simple CRDT that contains an arbitrary value
along with an Ord
that tracks causality. It is the responsibility
of the user to guarantee that the source of the causal element
is monotonic. Don't use timestamps unless you are comfortable
with divergence.
Fields
val: V
val
is the opaque element contained within this CRDT
marker: M
marker
should be a monotonic value associated with this val
Methods
impl<V: Val, M: Marker> LWWReg<V, M>
[src]
pub fn update(&mut self, val: V, marker: M) -> Result<(), Error>
[src]
Updates value witnessed by the given marker. An Err is returned if the given marker is exactly equal to the current marker
use crdts::LWWReg; let mut reg = LWWReg { val: 1, marker: 2 }; // updating with a smaller marker is a no-op assert!(reg.update(2, 1).is_ok()); assert_eq!(reg.val, 1); // updating with existing marker fails assert!(reg.update(2, 2).is_err()); assert_eq!(reg, LWWReg { val: 1, marker: 2 }); // updating with same val and marker succeeds assert!(reg.update(1, 2).is_ok()); assert_eq!(reg, LWWReg { val: 1, marker: 2 }); // updating with descendent marker succeeds assert!(reg.update(2, 3).is_ok()); assert_eq!(reg, LWWReg { val: 2, marker: 3 });
Trait Implementations
impl<V: Val, M: Marker> FunkyCvRDT for LWWReg<V, M>
[src]
type Error = Error
User chosen error type
fn merge(
&mut self,
LWWReg { val: val, marker: marker }: Self
) -> Result<(), Error>
[src]
&mut self,
LWWReg { val: val, marker: marker }: Self
) -> Result<(), Error>
Combines two LWWReg
instances according to the marker that
tracks causality. Returns an error if the marker is identical but the
contained element is different.
use crdts::{LWWReg, FunkyCvRDT}; let mut l1 = LWWReg { val: 1, marker: 2 }; let l2 = LWWReg { val: 3, marker: 2 }; // errors! assert!(l1.merge(l2).is_err());
impl<V: Val, M: Marker> FunkyCmRDT for LWWReg<V, M>
[src]
type Error = Error
User chosen error type
type Op = Self
Same Op laws from non-funky CmRDT above
fn apply(&mut self, op: Self::Op) -> Result<(), Error>
[src]
impl<V: Clone + Val, M: Clone + Marker> Clone for LWWReg<V, M>
[src]
fn clone(&self) -> LWWReg<V, M>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<V: Eq + Val, M: Eq + Marker> Eq for LWWReg<V, M>
[src]
impl<V: Val + Default, M: Marker + Default> Default for LWWReg<V, M>
[src]
impl<V: PartialEq + Val, M: PartialEq + Marker> PartialEq<LWWReg<V, M>> for LWWReg<V, M>
[src]
impl<V: Hash + Val, M: Hash + Marker> Hash for LWWReg<V, M>
[src]
fn hash<__HVM: Hasher>(&self, state: &mut __HVM)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<V: Debug + Val, M: Debug + Marker> Debug for LWWReg<V, M>
[src]
impl<V: Val, M: Marker> Serialize for LWWReg<V, M> where
V: Serialize,
M: Serialize,
[src]
V: Serialize,
M: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de, V: Val, M: Marker> Deserialize<'de> for LWWReg<V, M> where
V: Deserialize<'de>,
M: Deserialize<'de>,
[src]
V: Deserialize<'de>,
M: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<V, M> Sync for LWWReg<V, M> where
M: Sync,
V: Sync,
M: Sync,
V: Sync,
impl<V, M> Unpin for LWWReg<V, M> where
M: Unpin,
V: Unpin,
M: Unpin,
V: Unpin,
impl<V, M> Send for LWWReg<V, M> where
M: Send,
V: Send,
M: Send,
V: Send,
impl<V, M> UnwindSafe for LWWReg<V, M> where
M: UnwindSafe,
V: UnwindSafe,
M: UnwindSafe,
V: UnwindSafe,
impl<V, M> RefUnwindSafe for LWWReg<V, M> where
M: RefUnwindSafe,
V: RefUnwindSafe,
M: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> Val for T where
T: PartialEq<T> + Clone + Debug,
[src]
T: PartialEq<T> + Clone + Debug,
impl<T> Val for T where
T: Clone + Debug,
[src]
T: Clone + Debug,
impl<T> Member for T where
T: Eq + Clone + Hash + Debug,
[src]
T: Eq + Clone + Hash + Debug,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
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.
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.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,