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
impl Delta
Sourcepub fn expected_base_len(&self) -> usize
pub fn expected_base_len(&self) -> usize
Chars of base the Retain/Delete ops together consume — the base
length this delta was built against.
Sourcepub fn apply(&self, base: &str) -> String
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.
Sourcepub fn try_apply(&self, base: &str) -> Result<String, BaseLengthMismatch>
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Delta
impl<'de> Deserialize<'de> for Delta
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Delta, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Delta, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Delta
Source§impl Serialize for Delta
impl Serialize for Delta
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.