RS.CLIPPY.COLLAPSIBLE_STR_REPLACE
Collapse consecutive calls to str::replace (2 or more) into a single call
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: collapsible_str_replace. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for consecutive calls to str::replace (2 or more)
that can be collapsed into a single call.
Why is this bad?
Consecutive str::replace calls scan the string multiple times
with repetitive code.
Example
let hello = "hesuo worpd"
.replace(\'s\', "l")
.replace("u", "l")
.replace(\'p\', "l");
Use instead:
let hello = "hesuo worpd".replace([\'s\', \'u\', \'p\'], "l");
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)