.clone()
in assignment RS-W1070Consider 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.
fn foo(v: &mut Bar) {
let h = Bar::new();
// work with h
*v = h.clone();
}
fn foo(v: &mut Bar) {
let h = Bar::new();
// work with h
v.clone_from(&h);
}