Skip to main content

Delta

Struct Delta 

Source
pub struct Delta {
    pub ops: Vec<Op>,
}
Expand description

A per-field edit against a base content. Ops apply left-to-right, consuming base positions; Retain/Delete advance the base cursor, Insert adds new text. USV throughout.

Serializes as { "ops": [ {"retain": n} | {"insert": s} | {"delete": n} ] } — plain, structured-clone-able data an editor bridge stores in a change record and maps its own positions through (map_pos). The serde shape is the wire the rebase codec and applyChange bundle carry across the language bindings.

Fields§

§ops: Vec<Op>

Implementations§

Source§

impl Delta

Source

pub fn expected_base_len(&self) -> usize

Chars of base the Retain/Delete ops together consume — the base length this delta was built against.

Source

pub fn apply(&self, base: &str) -> String

Apply to base, producing the new text. Base beyond what the ops consume is retained implicitly — a short delta names only the region it changes (a bare prepend, an edit near the start) and the untouched remainder carries through. Panics if the ops consume more base than exists (expected_base_len() > base.chars().count()): a delta built against a longer revision. This is the trusted-provenance path; clamping an over-long delta silently is corruption, so where the base’s provenance isn’t already trusted use Self::try_apply, which returns the mismatch as an error instead.

Source

pub fn try_apply(&self, base: &str) -> Result<String, BaseLengthMismatch>

Self::apply, but returns BaseLengthMismatch instead of panicking when the ops consume more base than base has — a delta built against a longer revision. Implicit trailing retain is the contract: a short delta (ops consuming less than base) is accepted and the untouched remainder is retained, matching map_pos’s implicit trailing retain so a producer that names only the changed region need not pad a bare trailing Op::Retain.

Cost of the leniency: a short delta carries no full-base-length check, so one replayed against a wrong but longer base applies silently instead of failing. An abbreviated delta forfeits that tripwire by construction; over-consumption still fails.

Source

pub fn map_pos(&self, pos: usize, assoc: Assoc) -> usize

Map a base char position to its new position. assoc decides the side of a same-position insertion (After moves past it).

Trait Implementations§

Source§

impl Clone for Delta

Source§

fn clone(&self) -> Delta

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Delta

Source§

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

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

impl<'de> Deserialize<'de> for Delta

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Delta, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Delta

Source§

impl PartialEq for Delta

Source§

fn eq(&self, other: &Delta) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Delta

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Delta

Auto Trait Implementations§

§

impl Freeze for Delta

§

impl RefUnwindSafe for Delta

§

impl Send for Delta

§

impl Sync for Delta

§

impl Unpin for Delta

§

impl UnsafeUnpin for Delta

§

impl UnwindSafe for Delta

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.