Overloading the assignment operator and adding C++ -like constructors have all been discussed in the past.
One of Rust's fundamental building blocks is that assignment is nothing more than a move (via memcpy
or the like). I think giving up this property would be way too much of a price to pay for some specialized use cases that would be somewhat easier to write.
That in itself doesn't need overloading =
. It only needs overloading operators that correspond to the RHS, which are probably already overloadable today (multiplication, addition and subtraction being the most common operations in linear algebra, so you could do this today.) You can then perform complex symbolic manipulations by making these operators return basically AST builders or partial ASTs or something along these lines. Then, in the end, you would indeed need one explicit e.g. function call to put the result in a buffer. (Not necessarily From
/Into
as they force a return-by-value, and one usually uses buffers if one wants to avoid intermediate allocations or reuse an existing allocation).
So you don't get everything with this approach, but you get almost everything. And that one call at the end shouldn't be too much of a burden – while it also has the added value that you see where the actual computation happens (and e.g. where the real performance bottleneck might be). (Conversely, overloading =
would mean that for every assignment in the code, you would now wonder if it's a simple memcpy or something which will take half a day to run and launch the nukes.)