[rust-dev] &self/&mut self in traits considered harmful(?)

Tommi rusty.gates at icloud.com
Wed Jun 11 11:47:44 PDT 2014

On 2014-06-11, at 21:33, Daniel Micay <danielmicay at gmail.com> wrote:

> Cloning big integers, rationals based on big integers or arbitrary
> precision floating point values for every single operation has a high
> cost.

I didn't say that all functions should start taking their arguments by value. I said `Mul` and similar should do it, i.e. functions that take a variable and return a variable of that same type. Instead of passing by reference and making a clone of the passed reference inside those functions, you force the caller to make the clone and mutate the passed argument in place. This enables the C++ like rvalue reference optimization for functions like multiplication.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140611/c93cf7ab/attachment.html>

More information about the Rust-dev mailing list