-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
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.
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
pcwalton commentedon Jun 12, 2013
I don't think that this is backwards incompatible.
thestinger commentedon Jun 12, 2013
@pcwalton: agreed, this shouldn't break anything, it's just an extra method/trait
graydon commentedon Aug 1, 2013
just a bug, removing milestone/nomination.
sanxiyn commentedon Oct 24, 2013
Tagging RFC.
thestinger commentedon Nov 2, 2013
I think this would be better as a default method on
Clone
rather than a trait.Merge pull request rust-lang#4329 from RalfJung/no-casts