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

Corey Richardson corey at octayn.net
Thu Jun 12 10:18:56 PDT 2014


Or bound by Copy.

On Thu, Jun 12, 2014 at 10:17 AM, Patrick Walton <pwalton at mozilla.com> wrote:
> 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.
>
> _______________________________________________
> 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