feat: trait 接口系统 — trait Show { fn method } + extend Trait Struct { }
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
trait Show {
|
||||
fn show(self: Self) -> void;
|
||||
}
|
||||
|
||||
struct Point { x: i64, y: i64 }
|
||||
|
||||
extend Show Point {
|
||||
fn show(self: Point) -> void {
|
||||
print_i64(self.x);
|
||||
print_i64(self.y);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> i64 {
|
||||
let p = Point { x: 10, y: 20 };
|
||||
p.show();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user