-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trait inheritance/composition #2616
Comments
Though this is an old bug, it's still useful since inheritance isn't quite finished yet. I moved it from enhancement => completion. |
struct Point {
mut x: int,
mut y: int
}
trait Positioned {
fn X()-> int;
fn Y()-> int;
fn SetX(int);
fn SetY(int);
}
trait Movable: Positioned {
fn translate(dx: int, dy: int) {
self.SetX(self.X() + dx);
self.SetY(self.Y() + dy);
}
}
struct Entity {
mut pos: Point,
}
impl Entity: Positioned {
fn X()-> int { self.pos.x }
fn Y()-> int { self.pos.y }
fn SetX(v: int) { self.pos.x = v; }
fn SetY(v: int) { self.pos.y = v; }
}
impl Entity: Movable { }
fn main() {
let mut e: Entity = Entity {
pos: Point {x: 0, y: 0},
};
io::println(fmt!("%?, %?", e.X(), e.Y()));
e.translate(5, 10);
io::println(fmt!("%?, %?", e.X(), e.Y()));
} "error: attempted access of field If you change the Movable.translate method to: trait Movable: Positioned {
fn translate(dx: int, dx: int) {
let s = self as Positioned;
s.SetX(s.X() + dx);
s.SetY(s.Y() + dy);
}
} It says: "error: failed to find an implementation of trait @positioned for self" |
@dustinlacewell I filed your bug as a separate issue: #3979 |
Inheritance basically works, closing the catchall bug. |
rustup With rust-lang#103360 having landed, I don't think we still need this `GetFileInformationByHandleEx` shim.
rustup With rust-lang#103360 having landed, I don't think we still need this `GetFileInformationByHandleEx` shim.
I know that there are multiple proposals floating around for how to do interface inheritance (of which traits may be one), but just noting it here so that FIXMEs can refer to issues.
The text was updated successfully, but these errors were encountered: