pub struct TextCrdt(/* private fields */);Expand description
A collaborative text CRDT based on RGA (Replicated Growable Array).
This is a thin wrapper around Rga<char> that provides text-specific
convenience methods like insert_str, remove_range, and Display.
§Example
use crdt_kit::prelude::*;
let mut t1 = TextCrdt::new(1);
t1.insert_str(0, "hello").unwrap();
let mut t2 = TextCrdt::new(2);
t2.insert_str(0, "world").unwrap();
t1.merge(&t2);
t2.merge(&t1);
// Both replicas converge to the same text.
assert_eq!(t1.to_string(), t2.to_string());Implementations§
Source§impl TextCrdt
impl TextCrdt
Sourcepub fn fork(&self, new_actor: NodeId) -> Self
pub fn fork(&self, new_actor: NodeId) -> Self
Create a fork of this replica with a different node ID.
Sourcepub fn insert(&mut self, index: usize, ch: char) -> Result<(), TextError>
pub fn insert(&mut self, index: usize, ch: char) -> Result<(), TextError>
Insert a character at the given visible index.
Sourcepub fn insert_str(&mut self, index: usize, s: &str) -> Result<(), TextError>
pub fn insert_str(&mut self, index: usize, s: &str) -> Result<(), TextError>
Insert a string at the given visible index.
Sourcepub fn remove(&mut self, index: usize) -> Result<(), TextError>
pub fn remove(&mut self, index: usize) -> Result<(), TextError>
Remove (tombstone) the character at the given visible index.
Trait Implementations§
Source§impl DeltaCrdt for TextCrdt
impl DeltaCrdt for TextCrdt
impl Eq for TextCrdt
impl StructuralPartialEq for TextCrdt
Auto Trait Implementations§
impl Freeze for TextCrdt
impl RefUnwindSafe for TextCrdt
impl Send for TextCrdt
impl Sync for TextCrdt
impl Unpin for TextCrdt
impl UnsafeUnpin for TextCrdt
impl UnwindSafe for TextCrdt
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