feat: impl 关键字改为 extend
This commit is contained in:
@@ -297,10 +297,10 @@ fn print_point(p: Point) -> void {
|
||||
}
|
||||
```
|
||||
|
||||
### impl — 方法
|
||||
### extend — 方法
|
||||
|
||||
```rust
|
||||
impl Point {
|
||||
extend Point {
|
||||
fn new(x: i64, y: i64) -> Point {
|
||||
return Point { x: x, y: y };
|
||||
}
|
||||
@@ -314,7 +314,7 @@ let p = Point.new(10, 20); // 方法调用
|
||||
print_i64(p.get_x()); // 10
|
||||
```
|
||||
|
||||
- `impl StructName { fn ... }` 定义方法
|
||||
- `extend StructName { fn ... }` 为结构体扩展方法
|
||||
- 第一个参数必须是 `self: StructName`
|
||||
- 调用: `instance.method(args)`
|
||||
|
||||
@@ -456,7 +456,7 @@ struct Student {
|
||||
score: i64,
|
||||
}
|
||||
|
||||
impl Student {
|
||||
extend Student {
|
||||
fn new(id: i64, score: i64) -> Student {
|
||||
return Student { name_id: id, score: score };
|
||||
}
|
||||
@@ -570,7 +570,7 @@ l_lang.exe source.l --emit-ir
|
||||
函数: fn name(p: T) -> Ret { return expr; }
|
||||
结构体: struct Name { f: Type } Name { f: val }
|
||||
枚举: enum Name { A, B, C } Name::B
|
||||
方法: impl T { fn m(self: T) } obj.m()
|
||||
方法: extend T { fn m(self: T) } obj.m()
|
||||
内建: print_i64 print_f64 print_bool print_str
|
||||
运算符: + - * / % == != < > <= >= && || ! += -= *= /=
|
||||
注释: // 行注释 /* 块注释 */
|
||||
|
||||
Reference in New Issue
Block a user