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

Corey Richardson corey at octayn.net
Wed Jun 11 11:52:47 PDT 2014


Keeping in mind that the `self` value here can be a reference. Ie,
implementing the traits also for references to a type.

On Wed, Jun 11, 2014 at 11:47 AM, Tommi <rusty.gates at icloud.com> wrote:
> 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.
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>



-- 
http://octayn.net/


More information about the Rust-dev mailing list