On 2013-11-15, at 9:46, Isaac Dupree <[email protected]> wrote:
> On 11/14/2013 09:25 PM, Tommi wrote:
>>>>
>>>>> trait Inflate {
>>>>> fn get_radius<'s>(&'s mut self) -> &'s mut int;
>>>>>
>>>>> fn inflate_by(&mut self, amount: int) {
>>>>> *self.get_radius() += amount;
>>>>> }
>>>>> }
>>>>> [...]
>
>> Third time's the charm. One more detail was still missing:
>>
>> struct Inflate {
>> virtual void inflate_by(int amount) = 0;
>> };
>> [...]
>
> Thing is, if all you have is an Inflate*, you're going to have to make a
> virtual function call to access that member.
But that's not any different from Rust. If all you have is @Inflate, then any
method call through that is a virtual function call.
> The goal is to have member access that works across several similar concrete
> types, without the speed cost of accessing a vtable.
In my C++ example, if you have an object of the concrete type Balloon, then I
don't think there's any vtable involved in a call to balloon->inflate_by(x).
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev