let s = s.replace("(", "");
let s = s.replace(")", "");
let s = s.replace(",", "");
let s = s.replace("\"", "");
let s = s.replace(".", "");
let s = s.replace(";", "");
let s = s.replace(":", "");
let s = s.replace("\'", "");
This code is executed for every word/token in a 30GB archive. As a result, speed is important. What is the fastest way (without unreasonable code complexity) to do this?
Explanation: str (and T where T: Deref<str>) has a function named replace (Which you have used already) and its argument for the pattern to look for it is P: Pattern<'a>, and looking at what it's been implemented for, it seems that &'a [char] would fit the problem at hand. (Look at the description)
How often do these occur in the string? If it's a lot (many replacements per string -> many moves to shuffle all the later chars backwards), consider something like string.chars().filter(..).collect(). Benchmark, but you might find this one-pass model is worth considering.
Personally, I'd just use Regex until it became more than two problems
That is true for Debug builds, if you try Release the replace() method seems to be fastest (however the difference between them in Release is much much smaller)
What is retain() doing under the hood that is different from chars().filter().collect()? I feel like the retain src code makes sense but can't figure out what filter does under the surface.