pub struct Replica { /* private fields */ }Implementations§
Source§impl Replica
impl Replica
Sourcepub fn new(id: NonZeroU32, initial_length: usize) -> Self
pub fn new(id: NonZeroU32, initial_length: usize) -> Self
The id must be unique among replicas of the same document. The initial
content is credited to this replica’s clock, so replicas joining an
existing session must fork one that’s already in it
rather than call new themselves.
Sourcepub fn fork(&self, new_id: NonZeroU32) -> Self
pub fn fork(&self, new_id: NonZeroU32) -> Self
A copy of this replica that authors its own edits under a new id.
pub fn is_empty(&self) -> bool
Sourcepub fn inserted(
&mut self,
byte_offset: usize,
length: usize,
) -> Result<Insertion>
pub fn inserted( &mut self, byte_offset: usize, length: usize, ) -> Result<Insertion>
Informs the replica that length bytes were inserted at the given
visible offset in the caller’s buffer, returning the op to send to the
other replicas.
Sourcepub fn deleted(&mut self, byte_range: Range<usize>) -> Result<Deletion>
pub fn deleted(&mut self, byte_range: Range<usize>) -> Result<Deletion>
Informs the replica that the given visible byte range was deleted from the caller’s buffer, returning the op to send to the other replicas. Note [Deletion by id]
Sourcepub fn integrate_insertion(&mut self, op: &Insertion) -> Vec<BufferEdit>
pub fn integrate_insertion(&mut self, op: &Insertion) -> Vec<BufferEdit>
Integrates another replica’s Insertion, returning the edits to
apply to the caller’s buffer, in order: the op itself and any pending
ops it unblocked. Empty when the op is a duplicate, empty, or must wait
for its causal dependencies. Note [Pending ops]
Sourcepub fn integrate_deletion(&mut self, op: &Deletion) -> Vec<BufferEdit>
pub fn integrate_deletion(&mut self, op: &Deletion) -> Vec<BufferEdit>
Integrates another replica’s Deletion, returning the edits to apply
to the caller’s buffer. Empty when nothing new was deleted or the op
must wait for its causal dependencies. Note [Deletion by id]