Skip to main content

PreparedEdits

Struct PreparedEdits 

Source
pub struct PreparedEdits<'source> { /* private fields */ }
Expand description

Validated, sorted byte edits bound to one immutable source revision.

Application metadata may retain at most 64 KiB of coalesced insertion text to accelerate repeated same-offset runs while preserving every logical edit. The optional complete output cache is initialized only by Self::rendered_text and can be released with Self::clear_rendered_text.

Implementations§

Source§

impl<'source> PreparedEdits<'source>

Source

pub fn apply(&self) -> AppliedText

Applies the already-prepared edits with one output allocation.

This does not retain an output-sized cache unless the caller explicitly initialized one through Self::rendered_text.

Source

pub fn apply_into(&self, output: &mut String) -> ApplySummary

Applies into caller-owned storage, retaining its allocation for replay.

The output is cleared only after this plan has already completed all exact-before, Unicode-boundary, overlap, and hard-limit validation. Reusing the same String therefore removes allocator traffic without weakening the all-or-nothing admission contract. When the caller has explicitly initialized Self::rendered_text, replay becomes one contiguous copy; otherwise this walks the normalized edit list without retaining an output-sized cache.

Source

pub fn apply_into_bytes(&self, output: &mut Vec<u8>) -> ApplySummary

Applies into a caller-owned byte buffer, retaining its allocation.

The bytes are guaranteed to be valid UTF-8 because the source and every replacement are validated Rust strings. This avoids a temporary String when the next stage is a file, socket, hash, or byte pipeline. When the caller has explicitly initialized Self::rendered_text, replay becomes one contiguous copy; otherwise this walks the normalized edit list without retaining an output-sized cache.

Source

pub fn rendered_text(&self) -> &str

Returns a lazily materialized, cached view of the complete output.

This is the zero-copy replay surface for consumers that can borrow the result. The first call allocates and renders the output; later calls are constant-time. Streaming through Self::chunks or Self::write_to does not initialize this cache.

Source

pub fn has_rendered_text(&self) -> bool

Returns whether Self::rendered_text currently retains an output-sized materialization.

Source

pub fn clear_rendered_text(&mut self)

Releases the optional output-sized materialization.

The normalized edit plan remains valid and later uncached applications still use the same atomic admission result.

Source

pub fn chunks(&self) -> EditChunks<'_>

Iterates over the validated output without allocating a final String.

This is the sink-independent streaming surface. Callers can forward the borrowed chunks to synchronous or asynchronous writers without adding an async runtime dependency to this crate.

Source

pub fn changes(&self) -> PreparedChanges<'_>

Iterates exact normalized changes without constructing output or a diff.

Source and output ranges are UTF-8 byte ranges. Multiple inserts at one source offset retain deterministic input order and receive consecutive output ranges. Identical replacements merged by Self::union retain every distinct provenance label.

Source

pub fn change_summary(&self) -> ChangeSummary

Returns exact edit and byte totals without applying or allocating output.

Source

pub fn write_to<W: Write + ?Sized>( &self, writer: &mut W, ) -> Result<WriteSummary>

Writes the already-validated result without allocating an output String.

Edit validation is atomic: construction of this value completed before the first write. An I/O failure can still leave a non-transactional sink with a prefix of the result, so callers requiring sink atomicity should write to a temporary file and rename it after success. This method does not call std::io::Write::flush or request durable storage synchronization.

Source

pub fn apply_with_validator( &self, validator: impl FnOnce(&str) -> bool, ) -> Result<AppliedText, EditError>

Applies edits and accepts only output approved by validator.

Source

pub fn union(self, other: Self) -> Result<Self, EditError>

Merges another prepared set over identical source text.

Inserts from self precede inserts from other at the same offset.

Source

pub fn invalidates_offset(&self, offset: usize) -> bool

Returns whether an offset lies strictly inside replaced/deleted source.

Source

pub fn map_offset_forward( &self, offset: usize, bias: OffsetBias, ) -> Option<usize>

Maps an original UTF-8 byte boundary into the resulting text.

Source

pub fn len(&self) -> usize

Source

pub fn bytes_before(&self) -> usize

Returns the immutable source size used to validate this plan.

Source

pub fn bytes_after(&self) -> usize

Returns the exact output size computed before application or streaming.

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Clone for PreparedEdits<'_>

Source§

fn clone(&self) -> Self

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<'source> Debug for PreparedEdits<'source>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'source> !Freeze for PreparedEdits<'source>

§

impl<'source> RefUnwindSafe for PreparedEdits<'source>

§

impl<'source> Send for PreparedEdits<'source>

§

impl<'source> Sync for PreparedEdits<'source>

§

impl<'source> Unpin for PreparedEdits<'source>

§

impl<'source> UnsafeUnpin for PreparedEdits<'source>

§

impl<'source> UnwindSafe for PreparedEdits<'source>

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.