pub struct PreprocessedText<'a> {
pub text: Cow<'a, str>,
pub original_end: usize,
pub mappings: Vec<LineMapping>,
}Expand description
Result of preprocessing text for multi-line concatenation.
text is a [Cow] so the overwhelmingly common passthrough/identity case
(a chunk with no structured-config shape and no multiline concatenation)
can BORROW the caller’s chunk bytes with zero allocation instead of paying a
full-body to_string() heap copy + memcpy on every chunk. Only the paths
that genuinely synthesize NEW bytes — multiline-joined concatenation,
structured-config key/value reassembly, homoglyph normalization — own a
String via Cow::Owned. Downstream consumers read text as &str via
Deref, so the borrow is internal to preprocessing.
Fields§
§text: Cow<'a, str>Original text (borrowed for passthrough) plus, for the synthesizing paths, appended multiline-joined / structured segments (owned).
original_end: usizeByte offset where appended joined segments start.
mappings: Vec<LineMapping>Mapping from offsets in text to original line numbers.
Implementations§
Source§impl<'a> PreprocessedText<'a>
impl<'a> PreprocessedText<'a>
Sourcepub fn line_for_offset(&self, offset: usize) -> Option<usize>
pub fn line_for_offset(&self, offset: usize) -> Option<usize>
Map a byte offset in preprocessed text back to an original line number.
Mappings are stored in start_offset-sorted, contiguous order
(the preprocessor appends them as it walks the input), so a
partition_point binary search resolves the lookup in
O(log L) instead of the prior O(L) linear scan. On a
10 000-line file with ~100 matches that’s 10 000 × 100 = 1 M
pointer compares cut to ~1 400.
Sourcepub fn passthrough(text: impl Into<Cow<'a, str>>) -> Self
pub fn passthrough(text: impl Into<Cow<'a, str>>) -> Self
Build a preprocessed representation with a one-line identity mapping.
Takes the text as a [Cow] so a byte-identical passthrough chunk can be
carried as Cow::Borrowed (zero allocation — no heap alloc or memcpy of
the chunk body) while a normalization-rewritten chunk passes its already-
owned String through as Cow::Owned. Only the per-line mappings
bookkeeping (size-independent of the body bytes) is allocated either way.
Trait Implementations§
Source§impl<'a> Clone for PreprocessedText<'a>
impl<'a> Clone for PreprocessedText<'a>
Source§fn clone(&self) -> PreprocessedText<'a>
fn clone(&self) -> PreprocessedText<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for PreprocessedText<'a>
impl<'a> RefUnwindSafe for PreprocessedText<'a>
impl<'a> Send for PreprocessedText<'a>
impl<'a> Sync for PreprocessedText<'a>
impl<'a> Unpin for PreprocessedText<'a>
impl<'a> UnsafeUnpin for PreprocessedText<'a>
impl<'a> UnwindSafe for PreprocessedText<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more