Struct ditto::text::Text
[−]
[src]
pub struct Text { /* fields omitted */ }
Text is a String
-like UTF-encoded growable string.
It contains a number of optimizations that improve
replacement and op execution performance on large strings.
Internally, Text is based on LSEQ. It allows op-based replication
via execute_op
and state-based replication
via merge
. State-based replication allows
out-of-order delivery but op-based replication does not.
Text has the following performance characteristics:
replace
: O(log N)execute_op
: O(log N)merge
: O(N1 + N2 + S1 + S2), where N1 and N2 are the number of values in each Text being merged, and S1 and S2 are the number of sites that have edited each Text being merged.
Methods
impl Text
[src]
pub fn new() -> Self
[src]
Constructs and returns a new Text CRDT with site id 1.
pub fn from_str(string: &str) -> Self
[src]
Constructs and returns a new Text CRDT from a string. The Text has site id 1.
pub fn len(&self) -> usize
[src]
Returns the number of unicode characters in the text.
pub fn is_empty(&self) -> bool
[src]
Returns true if the Text CRDT has a length of 0. Returns false otherwise.
pub fn replace(
&mut self,
idx: usize,
len: usize,
text: &str
) -> Option<Result<Op, Error>>
[src]
&mut self,
idx: usize,
len: usize,
text: &str
) -> Option<Result<Op, Error>>
Replaces the text in the range [idx..<idx+len] with new text.
Panics if the start or stop idx is larger than the Text
's
length, or if it does not lie on a char
boundary. If the
Text does not have a site id, it caches the op and returns an
AwaitingSiteId
error.
pub fn site_id(&self) -> SiteId
[src]
Returns the site id.
pub fn state(&self) -> TextState
[src]
Returns a borrowed CRDT state.
pub fn clone_state(&self) -> TextState<'static>
[src]
Returns an owned CRDT state of cloned values.
pub fn into_state(self) -> TextState<'static>
[src]
Consumes the CRDT and returns its state
pub fn from_state(
state: TextState,
site_id: Option<SiteId>
) -> Result<Self, Error>
[src]
state: TextState,
site_id: Option<SiteId>
) -> Result<Self, Error>
Constructs a new CRDT from a state and optional site id. If the site id is present, it must be nonzero.
pub fn local_value(&self) -> String
[src]
Returns the CRDT value's equivalent local value.
pub fn execute_op(&mut self, op: Op) -> Vec<LocalOp>
[src]
Executes an op and returns the equivalent local op.
This function assumes that the op always inserts values
from the correct site. For untrusted ops, used validate_and_execute_op
.
pub fn validate_and_execute_op(
&mut self,
op: Op,
site_id: SiteId
) -> Result<Vec<LocalOp>, Error>
[src]
&mut self,
op: Op,
site_id: SiteId
) -> Result<Vec<LocalOp>, Error>
Validates that an op only inserts elements from a given site id, then executes the op and returns the equivalent local op.
pub fn merge(&mut self, other: TextState) -> Result<(), Error>
[src]
Merges a remote CRDT state into the CRDT. The remote CRDT state must have a site id.
pub fn add_site_id(&mut self, site_id: SiteId) -> Result<Vec<Op>, Error>
[src]
Assigns a site id to the CRDT and returns any cached ops. If the CRDT already has a site id, it returns an error.
Trait Implementations
impl Debug for Text
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Clone for Text
[src]
fn clone(&self) -> Text
[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
impl PartialEq for Text
[src]
fn eq(&self, __arg_0: &Text) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Text) -> bool
[src]
This method tests for !=
.