Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

List

Struct List 

Source
pub struct List { /* private fields */ }
Expand description

Ordered list with stable positioning for CRDT operations.

List maintains a stable ordering of elements using Position keys in a BTreeMap. This design enables concurrent insertions without requiring coordination between distributed replicas.

§Key Features

  • Stable ordering: Elements maintain their relative positions even with concurrent modifications
  • Insertion anywhere: Can insert between any two existing elements
  • CRDT semantics: Proper merge behavior for distributed systems
  • Efficient access: O(log n) access by position, O(1) by index for small lists

§Usage Patterns

let mut list = List::new();

// Simple append operations
list.push("first");  // Returns index 0
list.push("second"); // Returns index 1

// Insert between existing elements using index
list.insert(1, "between").unwrap();

// Access by traditional index
assert_eq!(list.get(0).unwrap().as_text(), Some("first"));

// Advanced users can use Position for precise control
let pos1 = Position::new(1, 1);  // 1.0
let pos2 = Position::new(2, 1);  // 2.0
let middle = Position::between(&pos1, &pos2);
list.insert_at_position(middle, "advanced");

§Concurrent Operations

When two replicas insert at the same logical position, the rational number system ensures a consistent final order:

Replica A: ["item1", "item3"] -> inserts "item2" between them
Replica B: ["item1", "item3"] -> inserts "item4" between them

After merge: ["item1", "item2", "item4", "item3"]
(order determined by Position comparison)

Implementations§

Source§

impl List

Source

pub fn new() -> Self

Creates a new empty list

Source

pub fn len(&self) -> usize

Returns the number of items in the list (excluding tombstones)

Source

pub fn total_len(&self) -> usize

Returns the total number of items including tombstones

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty

Source

pub fn push(&mut self, value: impl Into<Value>) -> usize

Pushes a value to the end of the list Returns the index of the newly added element

Source

pub fn insert( &mut self, index: usize, value: impl Into<Value>, ) -> Result<(), CRDTError>

Inserts a value at a specific index

Source

pub fn get(&self, index: usize) -> Option<&Value>

Gets a value by index (0-based), filtering out tombstones

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut Value>

Gets a mutable reference to a value by index (0-based), filtering out tombstones

Source

pub fn insert_at_position( &mut self, position: Position, value: impl Into<Value>, )

Inserts a value at a specific position (advanced API)

Source

pub fn get_by_position(&self, position: &Position) -> Option<&Value>

Gets a value by position

Source

pub fn get_by_position_mut(&mut self, position: &Position) -> Option<&mut Value>

Gets a mutable reference to a value by position

Source

pub fn set(&mut self, index: usize, value: impl Into<Value>) -> Option<Value>

Sets a value at a specific index, returns the old value if present Only considers non-tombstone elements for indexing

Source

pub fn remove(&mut self, index: usize) -> Option<Value>

Removes a value by index (tombstones it for CRDT semantics) Only considers non-tombstone elements for indexing

Source

pub fn remove_by_position(&mut self, position: &Position) -> Option<Value>

Removes a value by position

Source

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

Returns an iterator over the values in order (excluding tombstones)

Source

pub fn iter_all(&self) -> impl Iterator<Item = &Value>

Returns an iterator over all values including tombstones

Source

pub fn iter_with_positions(&self) -> impl Iterator<Item = (&Position, &Value)>

Returns an iterator over position-value pairs in order

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Value>

Returns a mutable iterator over the values in order

Source

pub fn merge(&mut self, other: &List)

Merges another List into this one (CRDT merge operation)

Source

pub fn clear(&mut self)

Clears all items from the list

Source

pub fn to_vec(&self) -> Vec<Value>

Converts to a Vec of values (loses position information)

Trait Implementations§

Source§

impl Clone for List

Source§

fn clone(&self) -> List

Returns a duplicate 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 Debug for List

Source§

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

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

impl Default for List

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for List

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 From<List> for Value

Source§

fn from(value: List) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Value> for List

Source§

fn from_iter<T: IntoIterator<Item = Value>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for List

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for List

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 TryFrom<&Value> for List

Source§

type Error = CRDTError

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Data for List

Source§

impl Eq for List

Source§

impl StructuralPartialEq for List

Auto Trait Implementations§

§

impl Freeze for List

§

impl RefUnwindSafe for List

§

impl Send for List

§

impl Sync for List

§

impl Unpin for List

§

impl UnwindSafe for List

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

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

§

impl<M> Meta for M
where M: Default,