Struct ditto::register::Register
[−]
[src]
pub struct Register<T: Clone> { /* fields omitted */ }
A Register is a replaceable value that can be updated
via the update
function.
Register allows op-based replication via execute_op
and state-based replication via merge
.
Both replication methods are idempotent and can handle
out-of-order delivery.
Register
has a spatial complexity of O(N + S), where
N is the number of values concurrently held in the Register
and
S is the number of sites that have updated the Register
.
It has the following performance characteristics:
update
: O(1)execute_op
: O(N), where N is the number of values concurrently held in theRegister
.merge
: O(N + M), where N and M are the number of values concurrently held in theRegister
being merged into and theRegisterState
being merged, respectively.
Methods
impl<T: Clone> Register<T>
[src]
pub fn new(value: T) -> Self
[src]
Constructs and returns a new Register
with site id 1.
pub fn get(&self) -> &T
[src]
Returns a reference to the Register
's value.
pub fn update(&mut self, value: T) -> Result<Op<T>, Error>
[src]
Updates the Register
's value and returns an op
that can be replciated to other sites.
If the register does not have a site id allocated, it
caches the op and returns an AwaitingSiteId
error.
pub fn execute_op(&mut self, op: Op<T>) -> &T
[src]
Executes an Op and returns a reference to the new value if the value has changed. If the op has already been executed or superceded, nothing is done.
pub fn merge(&mut self, other: RegisterState<T>)
[src]
Merges remote state into the Register
pub fn add_site_id(&mut self, site_id: SiteId) -> Result<Option<Op<T>>, Error>
[src]
Assigns a site id and returns a cached op if it exists.
pub fn site_id(&self) -> SiteId
[src]
Returns the Register
's site id.
pub fn summary(&self) -> &Summary
[src]
Returns a reference to the Register
's summary.
pub fn state(&self) -> RegisterState<T>
[src]
Returns a borrowed RegisterState.
pub fn clone_state(&self) -> RegisterState<'static, T>
[src]
Returns an owned RegisterState of cloned values.
pub fn into_state(self) -> RegisterState<'static, T>
[src]
Consumes the Register and returns its RegisterState
pub fn from_state(
state: RegisterState<T>,
site_id: Option<SiteId>
) -> Result<Self, Error>
[src]
state: RegisterState<T>,
site_id: Option<SiteId>
) -> Result<Self, Error>
Constructs a new Register from a RegisterState and an optional site id. If the site id is given, it must be nonzero.
pub fn validate_and_execute_op(
&mut self,
op: Op<T>,
site_id: SiteId
) -> Result<&T, Error>
[src]
&mut self,
op: Op<T>,
site_id: SiteId
) -> Result<&T, Error>
Validates that an op comes from a specific site id, then executes the op.
Trait Implementations
impl<T: Debug + Clone> Debug for Register<T>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Clone + Clone> Clone for Register<T>
[src]
fn clone(&self) -> Register<T>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more