josh
7
replace_with is certainly general enough, but using it for this purpose would require something like:
let mut count = 0;
let replaced = some_str.replace_with("pattern", |something| { count += 1; "replacement" });
For the proposed use case, this seems like a substantially more cumbersome solution.
I'm not sure if replace_and_count is a sufficiently common use case to motivate putting it in the standard library, but I think replace_with may be excessively general for that use case.
2 Likes