Skip to main content

Patch

Struct Patch 

Source
pub struct Patch(/* private fields */);
Expand description

An ordered set of Edits — the one change currency.

Invariant (debug-asserted on every Patch::push): edits are sorted ascending and disjoint in both coordinate spaces (touching is allowed).

Implementations§

Source§

impl Patch

Source

pub fn new() -> Self

An empty patch (maps every position to itself).

Source

pub fn single(edit: Edit) -> Self

A patch of a single edit.

Source

pub fn edits(&self) -> &[Edit]

The edits, in ascending order.

Source

pub fn is_empty(&self) -> bool

Whether the patch changes nothing.

Source

pub fn push(&mut self, edit: Edit)

Append an edit. Debug-panics if it breaks the ascending-disjoint invariant in either coordinate space.

Source

pub fn map_offset(&self, offset: u32, bias: Bias) -> u32

Map a pre-edit byte offset to its post-edit offset (the transit table).

bias only matters when offset sits exactly on an insertion point: Left keeps it before the inserted text, Right moves it after.

Source

pub fn map_range( &self, range: Range<u32>, start_bias: Bias, end_bias: Bias, ) -> Range<u32>

Map a pre-edit byte range, biasing each endpoint independently, and never inverting: if the mapped start would exceed the mapped end, both collapse to the mapped end.

Source

pub fn map_many(&self, queries: &[(u32, Bias)], out: &mut Vec<u32>)

Map a batch of offsets — each with its own Bias — through the patch, appending results to out in query order. Semantically each entry is exactly map_offset(offset, bias), but the batch builds a prefix-shift index once (O(edits)) and binary-searches per query (O(log edits)), so the whole call is O(edits + queries·log edits) instead of the per-offset loop’s O(queries·edits). That is the difference between O(C²) and O(C) when a document-scale multi-cursor edit produces a C-edit patch and every derived view (C selections, N decorations, F fold openers) must rebase through it.

No ordering precondition on queries — the binary search makes it order-independent, so nested/overlapping ranges (decorations) are fine.

Trait Implementations§

Source§

impl Clone for Patch

Source§

fn clone(&self) -> Patch

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 Patch

Source§

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

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

impl Default for Patch

Source§

fn default() -> Patch

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

Auto Trait Implementations§

§

impl Freeze for Patch

§

impl RefUnwindSafe for Patch

§

impl Send for Patch

§

impl Sync for Patch

§

impl Unpin for Patch

§

impl UnsafeUnpin for Patch

§

impl UnwindSafe for Patch

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.