-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.P-lowLow priorityLow priority
Description
This would be very useful for core::num
(see #4819), and also mathematics libraries.
// overloads `+=`
#[lang="add_assign"]
trait AddAssign<RHS> {
fn add_assign(&mut self, &other: RHS);
}
// overloads `-=`
#[lang="sub_assign"]
trait SubAssign<RHS> {
fn sub_assign(&mut self, &other: RHS);
}
// overloads `*=`
#[lang="mul_assign"]
trait MulAssign<RHS> {
fn mul_assign(&mut self, &other: RHS);
}
// overloads `/=`
#[lang="quot_assign"]
trait QuotAssign<RHS> {
fn quot_assign(&mut self, &other: RHS);
}
// overloads `%=`
#[lang="rem_assign"]
trait RemAssign<RHS> {
fn rem_assign(&mut self, &other: RHS);
}
It would also be useful to be able to assign to values accessed via the index operator. This would return a mutable reference to the element. =, +=, -=, *=, /=, and %= would then be based off the overloads defined for that element type.
#[lang="index_assign"]
trait IndexAssign<Index,Element> {
fn mut_index<'a>(&'a mut self, index: Index) -> &'a mut Element;
}
Edit: Removed Assign
trait for =
operator.
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.P-lowLow priorityLow priority