pub struct VectorClock { /* private fields */ }Expand description
Vector clock for tracking causality in distributed systems Each instance maintains its own logical clock version
Implementations§
Source§impl VectorClock
impl VectorClock
Sourcepub fn new() -> VectorClock
pub fn new() -> VectorClock
Create a new empty vector clock
Sourcepub fn from_json(json: &str) -> Result<VectorClock, Error>
pub fn from_json(json: &str) -> Result<VectorClock, Error>
Create a vector clock from a JSON string
Sourcepub fn get(&self, instance_id: &str) -> i64
pub fn get(&self, instance_id: &str) -> i64
Get the version for a specific instance (0 if not present)
Sourcepub fn set(&mut self, instance_id: String, version: i64)
pub fn set(&mut self, instance_id: String, version: i64)
Set the version for a specific instance
Sourcepub fn increment(&mut self, instance_id: &str) -> i64
pub fn increment(&mut self, instance_id: &str) -> i64
Increment the version for the given instance
Sourcepub fn merge(&mut self, other: &VectorClock)
pub fn merge(&mut self, other: &VectorClock)
Merge another vector clock, taking the maximum version for each instance This is used when receiving updates from other instances
Sourcepub fn compare(&self, other: &VectorClock) -> ClockOrder
pub fn compare(&self, other: &VectorClock) -> ClockOrder
Compare this clock with another to determine causality relationship Returns:
- Before: self happened-before other (self is older)
- After: other happened-before self (self is newer)
- Concurrent: neither happened-before the other (conflict)
- Equal: clocks are identical
Sourcepub fn happens_before(&self, other: &VectorClock) -> bool
pub fn happens_before(&self, other: &VectorClock) -> bool
Check if this clock happened-before another (causally precedes)
Sourcepub fn is_concurrent(&self, other: &VectorClock) -> bool
pub fn is_concurrent(&self, other: &VectorClock) -> bool
Check if this clock is concurrent with another (conflict)
Sourcepub fn is_equal(&self, other: &VectorClock) -> bool
pub fn is_equal(&self, other: &VectorClock) -> bool
Check if this clock is equal to another
Sourcepub fn instance_count(&self) -> usize
pub fn instance_count(&self) -> usize
Get the number of instances tracked
Trait Implementations§
Source§impl Clone for VectorClock
impl Clone for VectorClock
Source§fn clone(&self) -> VectorClock
fn clone(&self) -> VectorClock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VectorClock
impl Debug for VectorClock
Source§impl Default for VectorClock
impl Default for VectorClock
Source§fn default() -> VectorClock
fn default() -> VectorClock
Source§impl<'de> Deserialize<'de> for VectorClock
impl<'de> Deserialize<'de> for VectorClock
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<VectorClock, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<VectorClock, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for VectorClock
impl Display for VectorClock
Source§impl PartialEq for VectorClock
impl PartialEq for VectorClock
Source§impl Serialize for VectorClock
impl Serialize for VectorClock
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for VectorClock
impl StructuralPartialEq for VectorClock
Auto Trait Implementations§
impl Freeze for VectorClock
impl RefUnwindSafe for VectorClock
impl Send for VectorClock
impl Sync for VectorClock
impl Unpin for VectorClock
impl UnwindSafe for VectorClock
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.