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. The goal is to have member access that works across several similar concrete types, without the speed cost of accessing a vtable.

(You could do it with a struct containing shared information plus a discriminated union (Rust enum) of all types that would have implemented the trait, but I imagine that has other downsides.)

-Isaac

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to