Struct OperationSeq

Source
pub struct OperationSeq { /* private fields */ }
Expand description

A sequence of Operations on text.

Implementations§

Source§

impl OperationSeq

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a store for operatations which does not need to allocate until capacity operations have been stored inside.

Source

pub fn compose(&self, other: &Self) -> Result<Self, OTError>

Merges the operation with other into one operation while preserving the changes of both. Or, in other words, for each input string S and a pair of consecutive operations A and B. apply(apply(S, A), B) = apply(S, compose(A, B)) must hold.

§Error

Returns an OTError if the operations are not composable due to length conflicts.

Source

pub fn delete(&mut self, n: u64)

Deletes n characters at the current cursor position.

Source

pub fn insert(&mut self, s: &str)

Inserts a s at the current cursor position.

Source

pub fn retain(&mut self, n: u64)

Moves the cursor n characters forwards.

Source

pub fn transform(&self, other: &Self) -> Result<(Self, Self), OTError>

Transforms two operations A and B that happened concurrently and produces two operations A’ and B’ (in an array) such that apply(apply(S, A), B') = apply(apply(S, B), A'). This function is the heart of OT.

§Error

Returns an OTError if the operations cannot be transformed due to length conflicts.

Source

pub fn apply(&self, s: &str) -> Result<String, OTError>

Applies an operation to a string, returning a new string.

§Error

Returns an error if the operation cannot be applied due to length conflicts.

Source

pub fn invert(&self, s: &str) -> Self

Computes the inverse of an operation. The inverse of an operation is the operation that reverts the effects of the operation, e.g. when you have an operation ‘insert(“hello “); skip(6);’ then the inverse is ‘delete(“hello “); skip(6);’. The inverse should be used for implementing undo.

Source

pub fn is_noop(&self) -> bool

Checks if this operation has no effect.

Source

pub fn base_len(&self) -> usize

Returns the length of a string these operations can be applied to

Source

pub fn target_len(&self) -> usize

Returns the length of the resulting string after the operations have been applied.

Source

pub fn ops(&self) -> &[Operation]

Returns the wrapped sequence of operations.

Trait Implementations§

Source§

impl Clone for OperationSeq

Source§

fn clone(&self) -> OperationSeq

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 OperationSeq

Source§

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

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

impl Default for OperationSeq

Source§

fn default() -> OperationSeq

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

impl FromIterator<Operation> for OperationSeq

Source§

fn from_iter<T: IntoIterator<Item = Operation>>(ops: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for OperationSeq

Source§

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

Auto Trait Implementations§

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.