Closed
Description
What it does
Warns when using push_str
with a single-character string literal, and push
with a char
would work fine.
Categories (optional)
- Kind:
clippy::style
andclippy::perf
(maybeclippy::pedantic
?)
What is the advantage of the recommended code over the original code?
- It's more obvious what's going on; after all, you're not trying to push a string, you're trying to push a character
- It should be more performant and reduce binary size to push a
char
, since it's just a number and will be inlined, than to push a&'static str
, which must be stored in the binary and accessed via a pointer
Drawbacks
None.
Example
let mut string = String::new();
string.push_str("R");
Could be written as:
let mut string = String::new();
string.push('R');