Rust

Rust

Made by DeepSource

Extending string with another using chars RS-W1095

Bug risk
Minor

Extending one String with another is possible through .extend(s.chars()). However, this is better expressed using push_str(s).

Bad practice

let mut greeting = String::from("Hello");
greeting.extend(", ".chars());

let name = String::from("Ferris");
greeting.extend(name.chars());

assert_eq!(greeting, "Hello, Ferris");

Recommended

let mut greeting = String::from("Hello");
greeting.push_str(", ");

let name = String::from("Ferris");
greeting.push_str(&name);

assert_eq!(greeting, "Hello, Ferris");