Closed
Description
At the moment, a = b.clone()
is the way to copy-assign to a value in generic code (at least once there's a default implementation for Copy
able types, per #3313).
If a
is uninitialized, that's perfectly optimal. When the value is already initialized, assignment can often be done with fewer allocations; a list or chunked list can be partially or fully reused, and even a vector/string can often be reused if it's big enough.
So, something like this (with a default impl for Clone
able types):
pub trait Assign<T>() {
fn assign(&mut self, other: &T) -> self;
}
a.assign(&b);
There's no need for any operator overload, since a = b
is just an implicit copy or a move.