Struct crdts::list::List

source ·
pub struct List<T, A: Ord> { /* private fields */ }
Expand description

As described in the module documentation:

A List is a CRDT for storing sequences of data (Strings, ordered lists). It provides an efficient view of the stored sequence, with fast index, insertion and deletion operations.

Implementations§

source§

impl<T, A: Ord + Clone> List<T, A>

source

pub fn new() -> Self

Create an empty List

source

pub fn insert_index(&self, ix: usize, val: T, actor: A) -> Op<T, A>

Generate an op to insert the given element at the given index. If ix is greater than the length of the List then it is appended to the end.

source

pub fn append(&self, c: T, actor: A) -> Op<T, A>

Create an op to insert an element at the end of the sequence.

source

pub fn delete_index(&self, ix: usize, actor: A) -> Option<Op<T, A>>

Create an op to delete the element at the given index.

Returns None if ix is out of bounds, i.e. ix > self.len().

source

pub fn len(&self) -> usize

Get the length of the List.

source

pub fn is_empty(&self) -> bool

Check if the List is empty.

source

pub fn read<'a, C: FromIterator<&'a T>>(&'a self) -> C

Read the List into a container of your choice

use crdts::{List, CmRDT};

let mut list = List::new();
list.apply(list.append('a', 'A'));
list.apply(list.append('b', 'A'));
list.apply(list.append('c', 'A'));
assert_eq!(list.read::<String>(), "abc");
source

pub fn read_into<C: FromIterator<T>>(self) -> C

Read the List into a container of your choice, consuming it.

use crdts::{List, CmRDT};

let mut list = List::new();
list.apply(list.append(1, 'A'));
list.apply(list.append(2, 'A'));
list.apply(list.append(3, 'A'));
assert_eq!(list.read_into::<Vec<_>>(), vec![1, 2, 3]);
source

pub fn iter(&self) -> impl Iterator<Item = &T>

Get the elements represented by the List.

source

pub fn iter_entries(&self) -> impl Iterator<Item = (&Identifier<OrdDot<A>>, &T)>

Get each elements identifier and value from the List.

source

pub fn position(&self, ix: usize) -> Option<&T>

Get an element at a position in the sequence represented by the List.

source

pub fn position_entry(&self, id: &Identifier<OrdDot<A>>) -> Option<usize>

Find an identifer by an index.

source

pub fn get(&self, id: &Identifier<OrdDot<A>>) -> Option<&T>

Finds an element by its Identifier.

source

pub fn first(&self) -> Option<&T>

Get first element of the sequence represented by the List.

source

pub fn first_entry(&self) -> Option<(&Identifier<OrdDot<A>>, &T)>

Get the first Entry of the sequence represented by the List.

source

pub fn last(&self) -> Option<&T>

Get last element of the sequence represented by the List.

source

pub fn last_entry(&self) -> Option<(&Identifier<OrdDot<A>>, &T)>

Get the last Entry of the sequence represented by the List.

Trait Implementations§

source§

impl<T: Clone, A: Clone + Ord> Clone for List<T, A>

source§

fn clone(&self) -> List<T, A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, A: Ord + Clone + Debug> CmRDT for List<T, A>

source§

fn apply(&mut self, op: Self::Op)

Apply an operation to an List instance.

If the operation is an insert and the identifier is already present in the List instance the result is a no-op

If the operation is a delete and the identifier is not present in the List instance the result is a no-op

§

type Op = Op<T, A>

Op defines a mutation to the CRDT. As long as Op’s from one actor are replayed in exactly the same order they were generated by that actor, the CRDT will converge. In other words, we must have a total ordering on each actors operations, while requiring only a partial order over all ops. E.g. Read more
§

type Validation = DotRange<A>

The validation error returned by validate_op.
source§

fn validate_op(&self, op: &Self::Op) -> Result<(), Self::Validation>

Some CRDT’s have stricter requirements on how they must be used. To avoid violating these requirements, CRDT’s provide an interface to optionally validate op’s before they are applied. Read more
source§

impl<T: Debug, A: Debug + Ord> Debug for List<T, A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, A: Ord> Default for List<T, A>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, T, A> Deserialize<'de> for List<T, A>where T: Deserialize<'de>, A: Deserialize<'de> + Ord,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Hash, A: Hash + Ord> Hash for List<T, A>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, A: Ord> IntoIterator for List<T, A>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoValues<Identifier<OrdDot<A>>, T, Global>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: PartialEq, A: PartialEq + Ord> PartialEq<List<T, A>> for List<T, A>

source§

fn eq(&self, other: &List<T, A>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, A> Serialize for List<T, A>where T: Serialize, A: Serialize + Ord,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq, A: Eq + Ord> Eq for List<T, A>

source§

impl<T, A: Ord> StructuralEq for List<T, A>

source§

impl<T, A: Ord> StructuralPartialEq for List<T, A>

Auto Trait Implementations§

§

impl<T, A> RefUnwindSafe for List<T, A>where A: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, A> Send for List<T, A>where A: Send, T: Send,

§

impl<T, A> Sync for List<T, A>where A: Sync, T: Sync,

§

impl<T, A> Unpin for List<T, A>

§

impl<T, A> UnwindSafe for List<T, A>where A: RefUnwindSafe, T: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,