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

Patrick Walton pwalton at mozilla.com
Thu Jun 12 10:17:19 PDT 2014

You could just clone the value to get around that error.

On June 12, 2014 10:03:40 AM PDT, Tommi <rusty.gates at icloud.com> wrote:
>On 2014-06-12, at 19:08, Patrick Walton <pcwalton at mozilla.com> wrote:
>> On 6/11/14 6:27 AM, SiegeLord wrote:
>>> So, I think the situation is pretty bad. What can be done to fix it?
>> Seems to me we can just make the overloaded operator traits take
>by-value self.
>I definitely wouldn't want to see something like the following:
>pub trait GreaterByOne<T> {
>    fn greater_by_one(self) -> Self;
>pub fn my_algorithm<X, T: GreaterByOne<X> + Add<T, T>>(value: T) -> T {
>    value.greater_by_one() +
>    value.greater_by_one() // error: use of moved value: `value`

Sent from my Android phone with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140612/e17f8433/attachment.html>

More information about the Rust-dev mailing list