Struct ditto::list::List
[−]
[src]
pub struct List<T: 'static> { /* fields omitted */ }
A List is a Vec
-like ordered sequence of elements.
List elements must implement the Clone
, Serialize
,
and Deserialize
traits.
Internally, List 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.
List's performance characteristics are similar to Vec:
Methods
impl<T: Clone> List<T>
[src]
pub fn new() -> Self
[src]
Constructs and returns a new List with site id 1.
pub fn len(&self) -> usize
[src]
Returns the number of elements in the list.
pub fn is_empty(&self) -> bool
[src]
Returns true if the List has a length of 0. Returns false otherwise
pub fn get(&self, idx: usize) -> Option<&T>
[src]
Returns a reference to the element at position idx
.
Returns None if idx is out-of-bounds.
pub fn push(&mut self, value: T) -> Result<Op<T>, Error>
[src]
Pushes a value onto the end of the list. If the list does
not have a site id, it caches the resulting op and returns an
AwaitingSiteId
error.
pub fn pop(&mut self) -> Option<(T, Result<Op<T>, Error>)>
[src]
Removes the value at the end of the list, if the list is nonempty.
If the list is empty, it returns None. If the pop succeeds but
the list does not have a site id, it caches the resulting op
and returns an AwaitingSiteId
error.
pub fn insert(&mut self, idx: usize, value: T) -> Result<Op<T>, Error>
[src]
Inserts a value at position idx
in the list, shifting all
elements after it to the right. Panics if the idx is out of
bounds. If the insert succeeds but the list does not have a
site id, it caches the resulting op and returns an
AwaitingSiteId
error.
pub fn remove(&mut self, idx: usize) -> (T, Result<Op<T>, Error>)
[src]
Removes the element at position idx
from the list,
shifting all elements after it to the left. Panics
if the idx is out-of-bounds. If the remove succeeds but
the list does not have a site id, it caches the resulting
op and returns an AwaitingSiteId
error.
pub fn site_id(&self) -> SiteId
[src]
Returns the site id.
pub fn state(&self) -> ListState<T>
[src]
Returns a borrowed CRDT state.
pub fn clone_state(&self) -> ListState<'static, T>
[src]
Returns an owned CRDT state of cloned values.
pub fn into_state(self) -> ListState<'static, T>
[src]
Consumes the CRDT and returns its state
pub fn from_state(
state: ListState<T>,
site_id: Option<SiteId>
) -> Result<Self, Error>
[src]
state: ListState<T>,
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) -> Vec<T>
[src]
Returns the CRDT value's equivalent local value.
pub fn execute_op(&mut self, op: Op<T>) -> Option<LocalOp<T>>
[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<T>,
site_id: SiteId
) -> Result<Option<LocalOp<T>>, Error>
[src]
&mut self,
op: Op<T>,
site_id: SiteId
) -> Result<Option<LocalOp<T>>, 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: ListState<T>) -> 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<T>>, 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<T: Debug + 'static> Debug for List<T>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Clone + 'static> Clone for List<T>
[src]
fn clone(&self) -> List<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
impl<T: PartialEq + 'static> PartialEq for List<T>
[src]
fn eq(&self, __arg_0: &List<T>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &List<T>) -> bool
[src]
This method tests for !=
.