pub struct Position {
pub numerator: i64,
pub denominator: u64,
pub unique_id: Uuid,
}Expand description
Represents a position in a CRDT list using rational numbers.
This type provides a stable ordering mechanism for list elements that allows insertion between any two existing elements without requiring renumbering. Each position consists of:
- A rational number (numerator/denominator) for ordering
- A unique UUID for deterministic tie-breaking
§Examples
use eidetica::crdt::doc::list::Position;
let pos1 = Position::new(10, 1);
let pos2 = Position::new(20, 1);
let between = Position::between(&pos1, &pos2);
assert!(pos1 < between);
assert!(between < pos2);Fields§
§numerator: i64Numerator of the rational number
denominator: u64Denominator of the rational number (always positive)
unique_id: UuidUnique identifier for deterministic ordering
Implementations§
Source§impl Position
impl Position
Sourcepub fn beginning() -> Self
pub fn beginning() -> Self
Creates a position at the beginning of the sequence.
§Examples
use eidetica::crdt::doc::list::Position;
let beginning = Position::beginning();
let after = Position::new(1, 1);
assert!(beginning < after);Sourcepub fn end() -> Self
pub fn end() -> Self
Creates a position at the end of the sequence.
§Examples
use eidetica::crdt::doc::list::Position;
let end = Position::end();
let before = Position::new(1000, 1);
assert!(before < end);Sourcepub fn between(left: &Position, right: &Position) -> Self
pub fn between(left: &Position, right: &Position) -> Self
Creates a position between two existing positions.
This method finds the rational number that falls between the two given positions and creates a new position with that value.
§Arguments
left- The left (smaller) positionright- The right (larger) position
§Examples
use eidetica::crdt::doc::list::Position;
let pos1 = Position::new(1, 1);
let pos2 = Position::new(3, 1);
let between = Position::between(&pos1, &pos2);
assert!(pos1 < between);
assert!(between < pos2);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 Ord for Position
impl Ord for Position
Source§impl PartialOrd for Position
impl PartialOrd for Position
impl Eq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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