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

Tommi rusty.gates at icloud.com
Thu Jun 12 10:03:40 PDT 2014


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`
}

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


More information about the Rust-dev mailing list