push_str
with single-character string literal "\n"
, use push
with a character literal instead262 s.push_str(". ");
263 }
264 if x % 8 == 7 {
265 s.push_str("\n");266 }
267 }
268 write!(f, "{}", s)
Using .insert_str()
or .push_str()
with a single-character string literal is
less clear than .insert()
or .push()
.
To improve readability, prefer .insert()
or .push()
when inserting or
pushing a single character to a String
.
let mut s = "Hello, world";
s.push_str("!");
let mut s = "Hello, world";
s.push('!');