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>
impl<'source> PreparedEdits<'source>
Sourcepub fn apply(&self) -> AppliedText
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.
Sourcepub fn apply_into(&self, output: &mut String) -> ApplySummary
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.
Sourcepub fn apply_into_bytes(&self, output: &mut Vec<u8>) -> ApplySummary
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.
Sourcepub fn rendered_text(&self) -> &str
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.
Sourcepub fn has_rendered_text(&self) -> bool
pub fn has_rendered_text(&self) -> bool
Returns whether Self::rendered_text currently retains an
output-sized materialization.
Sourcepub fn clear_rendered_text(&mut self)
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.
Sourcepub fn chunks(&self) -> EditChunks<'_> ⓘ
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.
Sourcepub fn changes(&self) -> PreparedChanges<'_> ⓘ
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.
Sourcepub fn change_summary(&self) -> ChangeSummary
pub fn change_summary(&self) -> ChangeSummary
Returns exact edit and byte totals without applying or allocating output.
Sourcepub fn write_to<W: Write + ?Sized>(
&self,
writer: &mut W,
) -> Result<WriteSummary>
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.
Sourcepub fn apply_with_validator(
&self,
validator: impl FnOnce(&str) -> bool,
) -> Result<AppliedText, EditError>
pub fn apply_with_validator( &self, validator: impl FnOnce(&str) -> bool, ) -> Result<AppliedText, EditError>
Applies edits and accepts only output approved by validator.
Sourcepub fn union(self, other: Self) -> Result<Self, EditError>
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.
Sourcepub fn invalidates_offset(&self, offset: usize) -> bool
pub fn invalidates_offset(&self, offset: usize) -> bool
Returns whether an offset lies strictly inside replaced/deleted source.
Sourcepub fn map_offset_forward(
&self,
offset: usize,
bias: OffsetBias,
) -> Option<usize>
pub fn map_offset_forward( &self, offset: usize, bias: OffsetBias, ) -> Option<usize>
Maps an original UTF-8 byte boundary into the resulting text.
pub fn len(&self) -> usize
Sourcepub fn bytes_before(&self) -> usize
pub fn bytes_before(&self) -> usize
Returns the immutable source size used to validate this plan.
Sourcepub fn bytes_after(&self) -> usize
pub fn bytes_after(&self) -> usize
Returns the exact output size computed before application or streaming.