Branch

Struct Branch 

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

This is used during fuzzing to make sure everything is working properly, and if not, find bugs as early as possible.

Source

pub fn dbg_assert_content_eq_rope(&self, expected_content: &JumpRope)

Source§

impl Branch

Source

pub fn merge(&mut self, oplog: &OpLog, merge_frontier: &[Time])

Add everything in merge_frontier into the set.

Reexposed as merge_changes.

Source§

impl Branch

Source

pub fn new() -> Self

Create a new (empty) branch at the start of history. The branch will be an empty list.

Source

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

Source

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().

Source

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!)

Source

pub fn local_version(&self) -> LocalVersion

Return the current version of the branch

Source

pub fn remote_version(&self, oplog: &OpLog) -> SmallVec<[RemoteId; 4]>

Return the current version of the branch in remote form

Source

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.

Source

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

Source

pub fn is_empty(&self) -> bool

Returns true if the document’s content is empty.

Source

pub fn make_delete_op(&self, loc: Range<usize>) -> Operation

Source

pub fn apply_local_operations( &mut self, oplog: &mut OpLog, agent: AgentId, ops: &[Operation], ) -> Time

Source

pub fn insert( &mut self, oplog: &mut OpLog, agent: AgentId, pos: usize, ins_content: &str, ) -> Time

Source

pub fn delete_without_content( &mut self, oplog: &mut OpLog, agent: AgentId, loc: Range<usize>, ) -> Time

Source

pub fn delete( &mut self, oplog: &mut OpLog, agent: AgentId, del_span: Range<usize>, ) -> Time

Source

pub fn into_inner(self) -> JumpRope

Consume the Branch and return the contained rope content.

Trait Implementations§

Source§

impl Clone for Branch

Source§

fn clone(&self) -> Branch

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 Branch

Source§

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

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

impl Default for Branch

Source§

fn default() -> Self

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

impl From<Branch> for JumpRope

Source§

fn from(branch: Branch) -> Self

Converts to this type from the input type.
Source§

impl From<Branch> for String

Source§

fn from(branch: Branch) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Branch

Source§

fn eq(&self, other: &Branch) -> 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 Eq for Branch

Source§

impl StructuralPartialEq for Branch

Auto Trait Implementations§

§

impl Freeze for Branch

§

impl RefUnwindSafe for Branch

§

impl Send for Branch

§

impl Sync for Branch

§

impl Unpin for Branch

§

impl UnwindSafe for Branch

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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

Source§

fn vzip(self) -> V