Skip to main content

escape_into

Function escape_into 

Source
pub fn escape_into(text: &str, out: &mut String)
Expand description

Encode the five characters that let a value stop being a value, into a buffer the caller already has.

The form the emitters use. escape is this with a String allocated around it, and the allocation is the whole difference: a described screen escapes once per attribute and once per run of text, so a function that returns a String allocates a few thousand times to produce one page, where a template engine writes its escaped bytes straight into the output buffer. Measured 2026-08-14 against a real pane, that gap was 85% of a 42x rendering cost, and this is the half of the fix that lives in this crate.

Sound in element text and in a double-quoted attribute alike, which is the property textContent-based escaping cannot have. Both sinks are covered by one function so that no call site has to choose, here or downstream.

Copies in runs rather than per character. All five encoded characters are ASCII, so a byte scan cannot land inside a multi-byte character and the slice between two of them is always a valid &str. Text with nothing to encode — which is most text — is one push_str of the whole thing.