Skip to main content

ChangeSet

Struct ChangeSet 

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

An ordered, position-composable set of changes.

Construct with ChangeSet::builder; the ops are private because the canonical form (merged runs, Delete before Insert at a replacement site) is an invariant that compose and map_pos rely on.

Implementations§

Source§

impl ChangeSet

Source

pub fn builder(len_before: usize) -> ChangeSetBuilder

Source

pub fn identity(len: usize) -> Self

The no-op change over a document of len chars.

Source

pub fn replace( len_before: usize, from: usize, to: usize, text: impl Into<String>, ) -> Self

A single replacement: replace chars from..to with text. The common shape for a keystroke, a paste, or one hunk of an agent diff.

Source

pub fn len_before(&self) -> usize

Source

pub fn len_after(&self) -> usize

Source

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

Source

pub fn is_identity(&self) -> bool

Whether this changes nothing (every char retained, nothing inserted).

Source

pub fn changed_span(&self) -> Option<ChangedSpan>

Source

pub fn apply(&self, text: &Rope) -> Rope

Produce the changed document. Does not mutate the input — the caller decides when a new revision becomes current.

Source

pub fn invert(&self, original: &Rope) -> ChangeSet

The changeset that undoes this one.

Needs the pre-image because Operation::Delete does not record what it deleted. Per ADR-0006 §6 this is called at apply time, while original is still the live document — calling it at undo time would hand it the post-image.

Source

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

Where pos (an index into the pre-image) lands in the post-image.

Positions inside a deleted range collapse to the start of the deletion — the text they pointed at is gone, and the start of what replaced it is the only honest answer. Callers that need to detect that case compare against the deletion instead of relying on the mapped value (ADR-0006 §4).

Source

pub fn touches(&self, from: usize, to: usize) -> RangeEffect

What this change did to from..to — a range something else is anchored to.

map_pos cannot answer this, by construction. It collapses a position inside a deleted range onto the deletion point, which is the same value it returns for a position at the deletion’s start that was never destroyed; and it sees nothing at all when text is inserted inside a range, since both endpoints shift cleanly. Both are exactly the signals ADR-0006 §4 cases 2 and 4 turn on, so they get their own traversal rather than being re-derived from the outside.

A zero-width range is an anchor: it counts as deleted only if the deletion strictly contains it, since a deletion merely starting there leaves it standing.

Source

pub fn compose(&self, other: &ChangeSet) -> ChangeSet

The single changeset equivalent to applying self and then other.

This is what lets a burst of keystrokes collapse into one undo step, and what a proposal is mapped through when the human has typed several times since it arrived.

Trait Implementations§

Source§

impl Clone for ChangeSet

Source§

fn clone(&self) -> ChangeSet

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 ChangeSet

Source§

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

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

impl Eq for ChangeSet

Source§

impl PartialEq for ChangeSet

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ChangeSet

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.