This is probably a previously asked question, but I couldn't find it on
Google, so...
Let's extend the Circle example from the guide a little:
struct Circle {
x:f64,
y:f64,
radius:f64,
}
trait HasArea {
fn area(&self)-> f64;
}
impl HasArea for Circle {
fn area(&self)-> f64 {
std::f64::consts::PI * (self.radius * self.radius)
}
}
struct Pancake {
circle: Circle,
is_tasty: bool,
}
...now, what is the easiest way I can implement HasArea for Pancake? I
could do this:
impl HasArea for Pancake {
fn area(&self) -> f64 { self.circle.area() }
}
...but that means a lot of boiler-plate code, especially if HasArea has
many methods. Hopefully rust will just inline/optimise the redirection
away in most cases to avoid the runtime cost, but is there a smarter or
more idiomatic way of doing this?
// David
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev