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

SiegeLord slabode at aim.com
Wed Jun 11 08:58:48 PDT 2014

On 06/11/2014 10:10 AM, Sebastian Gesemann wrote:
> On Wed, Jun 11, 2014 at 3:27 PM, SiegeLord wrote:
>> [...] Along the same lines, it is not immediately obvious
>> to me how to extend this lazy evaluation idea to something like num::BigInt.
>> So far, it seems like lazy evaluation will force dynamic dispatch in that
>> case which is a big shame (i.e. you'd store the operations in one array,
>> arguments in another and then play them back at the assignment time).
> I havn't tried something like expression templates in Rust yet. How
> did you come to the conclusion that it would require dynamic dispatch?

It's just the first idea I had with how this could work, but you're 
right, I can envision a way to do this without using dynamic dispatch. 
It'd look something like something like this: 
https://gist.github.com/SiegeLord/f1af81195df89ec04d10 . So, if nothing 
comes out of this discussion, at least you'd be able to do that. Note 
that the API is uglier, since you need to call 'eval' explicitly. 
Additionally, you need to manually borrow 'm' because you can't specify 
a lifetime of the &self argument in mul (another problem with 
by-ref-self methods).


More information about the Rust-dev mailing list