Struct yrs::StateVector
source · [−]pub struct StateVector(_);
Expand description
State vector is a compact representation of all known blocks inserted and integrated into a given document. This descriptor can be serialized and used to determine a difference between seen and unseen inserts of two replicas of the same document, potentially existing in different processes.
Another popular name for the concept represented by state vector is Version Vector.
Implementations
sourceimpl StateVector
impl StateVector
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns a number of unique clients observed by a document, current state vector corresponds to.
sourcepub fn contains(&self, id: &ID) -> bool
pub fn contains(&self, id: &ID) -> bool
Checks if current state vector includes given block identifier. Blocks, which identifiers can be found in a state vectors don’t need to be encoded as part of an update, because they were already observed by their remote peer, current state vector refers to.
sourcepub fn get(&self, client_id: &ClientID) -> u32
pub fn get(&self, client_id: &ClientID) -> u32
Get the latest clock sequence number value for a given client_id
as observed from
the perspective of a current state vector.
sourcepub fn inc_by(&mut self, client: ClientID, delta: u32)
pub fn inc_by(&mut self, client: ClientID, delta: u32)
Updates a state vector observed clock sequence number for a given client
by incrementing
it by a given delta
.
sourcepub fn set_min(&mut self, client: ClientID, clock: u32)
pub fn set_min(&mut self, client: ClientID, clock: u32)
Updates a state vector observed clock sequence number for a given client
by setting it to
a minimum value between an already present one and the provided clock
. In case if state
vector didn’t contain any value for that client
, a clock
value will be used.
sourcepub fn set_max(&mut self, client: ClientID, clock: u32)
pub fn set_max(&mut self, client: ClientID, clock: u32)
Updates a state vector observed clock sequence number for a given client
by setting it to
a maximum value between an already present one and the provided clock
. In case if state
vector didn’t contain any value for that client
, a clock
value will be used.
sourcepub fn iter(&self) -> Iter<'_, ClientID, u32>
pub fn iter(&self) -> Iter<'_, ClientID, u32>
Returns an iterator which enables to traverse over all clients and their known clock values described by a current state vector.
sourcepub fn merge(&mut self, other: Self)
pub fn merge(&mut self, other: Self)
Merges another state vector into a current one. Since vector’s clock values can only be incremented, whenever a conflict between two states happen (both state vectors have different clock values for the same client entry), a highest of these to is considered to be the most up-to-date.
Trait Implementations
sourceimpl Clone for StateVector
impl Clone for StateVector
sourcefn clone(&self) -> StateVector
fn clone(&self) -> StateVector
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for StateVector
impl Debug for StateVector
sourceimpl Decode for StateVector
impl Decode for StateVector
sourceimpl Default for StateVector
impl Default for StateVector
sourcefn default() -> StateVector
fn default() -> StateVector
Returns the “default value” for a type. Read more
sourceimpl Encode for StateVector
impl Encode for StateVector
sourceimpl PartialEq<StateVector> for StateVector
impl PartialEq<StateVector> for StateVector
sourcefn eq(&self, other: &StateVector) -> bool
fn eq(&self, other: &StateVector) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &StateVector) -> bool
fn ne(&self, other: &StateVector) -> bool
This method tests for !=
.
impl Eq for StateVector
impl StructuralEq for StateVector
impl StructuralPartialEq for StateVector
Auto Trait Implementations
impl RefUnwindSafe for StateVector
impl Send for StateVector
impl Sync for StateVector
impl Unpin for StateVector
impl UnwindSafe for StateVector
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more