InteriorAssign trait { a := b }
There are already traits such as AddAssign to implement +=.
It would be useful for code clarity if you could implement InteriorAssign to use :=.
This could be used to sugar syntax such as this:
data.ref_cell.replace(Some(new_value))
into this:
data.ref_cell := Some(new_value)
Which I personally find easier to read. And there is no ambiguity with =
The trait could look something like this:
pub trait InteriorAssign<Rhs = Self> {
fn assign(&self, rhs: Rhs);
}
Note the &self to allow this to be used for interior immutability.
There could be InteriorOpAssign versions that use &self for all the other operators as well:
InteriorAddAssign => :+=
InteriorSubAssign => :-=
Etc...
Bonus
As a bonus, (I'm not sure this can work) implement InteriorAccess to use ->
So instead of:
ref_cell.borrow_mut().some_method()
You can use:
ref_cell->some_method()
It might cause issues for the parser because it is used for function returns, but if not then this syntax could cut down a lot on a lot of boilerplate working with interior mutability.
Other symbol options:
ref_cell~>some_method()
ref_cell:.some_method()
ref_cell:->some_method()
Discussion in the ATmosphere