pub fn replace_chars<F>(s: &str, replacer: F) -> Cow<'_, str>Expand description
Replace characters efficiently with a mapping function
This function applies character replacements without unnecessary allocations when no replacements are needed. Uses a single-pass algorithm that borrows when no changes are needed and only allocates on first replacement found.
§Arguments
s- The input stringreplacer- Function that maps characters to their replacements
§Returns
A string with replacements applied, borrowing when no changes are needed