Rust

Rust

Made by DeepSource

Found use of .clone() in assignment RS-W1070

Anti-pattern
Minor

Consider using .clone_from() instead of assigning the result of .clone().

clone_from() may perform better in some cases because some structs may have custom implementations of clone_from(), which improve performance by avoiding needless allocations.

Bad practice

fn foo(v: &mut Bar) {
    let h = Bar::new();
    // work with h
    *v = h.clone();
}

Recommended

fn foo(v: &mut Bar) {
    let h = Bar::new();
    // work with h
    v.clone_from(&h);
}

References