Skip to content

Replace push_str with the corresponding operator #14872

Open
@leonardo-m

Description

@leonardo-m

What it does

This (probably pedantic) link suggests to replace calls to .push_str() with the corresponding operator.

Advantage

Shorter and more to the point code. And scripting language programmerer (as Python) are used to using operators for this.

Drawbacks

I don't know if there are drawbacks.

Example

fn main() {
    let mut msg = String::from("Hello");
    msg.push_str(", world");
    println!("{msg}"); // Hello, world
}

Could be written as:

fn main() {
    let mut msg = String::from("Hello");
    msg += ", world";
    println!("{msg}"); // Hello, world
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions