pub struct Branch { /* private fields */ }Expand description
A branch stores a checkout / snapshot of a document at some moment in time. Branches are the normal way for editors to interact with an OpLog, which stores the actual change set.
Internally, branches simply have two fields:
- Content (Ie, the list with all its values)
- Version
At the root version (the start of history), a branch is always empty.
Branches obey a very strict mutability rule: Whenever the content changes, the version
must change. A branch (with content at some named version) is always valid. But future changes
can always be merged in to the branch via branch.merge().
Branches also provide a simple way to edit documents, via the insert and
delete methods. These methods append new operations to the oplog, and modify
the branch to contain the named changes.
Implementations§
Source§impl Branch
This file contains debugging assertions to validate the document’s internal state.
impl Branch
This file contains debugging assertions to validate the document’s internal state.
This is used during fuzzing to make sure everything is working properly, and if not, find bugs as early as possible.
pub fn dbg_assert_content_eq_rope(&self, expected_content: &JumpRope)
Source§impl Branch
impl Branch
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new (empty) branch at the start of history. The branch will be an empty list.
Sourcepub fn new_at_local_version(oplog: &OpLog, version: &[Time]) -> Self
pub fn new_at_local_version(oplog: &OpLog, version: &[Time]) -> Self
Create a new branch as a checkout from the specified oplog, at the specified local time.
This method equivalent to calling oplog.checkout(version).
Sourcepub fn new_at_tip(oplog: &OpLog) -> Self
pub fn new_at_tip(oplog: &OpLog) -> Self
Create a new branch as a checkout from the specified oplog by merging all changes into a
single view of time. This method equivalent to calling
oplog.checkout_tip().
Sourcepub fn local_version_ref(&self) -> &[Time] ⓘ
pub fn local_version_ref(&self) -> &[Time] ⓘ
Return the current version of the branch as a &[usize].
This is provided because its slightly faster than calling local_version (since it prevents a clone(), and they’re weirdly expensive with smallvec!)
Sourcepub fn local_version(&self) -> LocalVersion
pub fn local_version(&self) -> LocalVersion
Return the current version of the branch
Sourcepub fn remote_version(&self, oplog: &OpLog) -> SmallVec<[RemoteId; 4]>
pub fn remote_version(&self, oplog: &OpLog) -> SmallVec<[RemoteId; 4]>
Return the current version of the branch in remote form
Sourcepub fn content(&self) -> &JumpRope
pub fn content(&self) -> &JumpRope
Return the current document contents. Note there is no mutable variant of this method because mutating the document’s content directly would violate the constraint that all changes must bump the document’s version.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the document’s content length.
Note this is different from the oplog’s length (which returns the number of operations).
pub fn make_delete_op(&self, loc: Range<usize>) -> Operation
pub fn apply_local_operations( &mut self, oplog: &mut OpLog, agent: AgentId, ops: &[Operation], ) -> Time
pub fn insert( &mut self, oplog: &mut OpLog, agent: AgentId, pos: usize, ins_content: &str, ) -> Time
pub fn delete_without_content( &mut self, oplog: &mut OpLog, agent: AgentId, loc: Range<usize>, ) -> Time
pub fn delete( &mut self, oplog: &mut OpLog, agent: AgentId, del_span: Range<usize>, ) -> Time
Sourcepub fn into_inner(self) -> JumpRope
pub fn into_inner(self) -> JumpRope
Consume the Branch and return the contained rope content.