File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -1684,7 +1684,20 @@ methods in such an implementation can only be used as direct calls on the
1684
1684
values of the type that the implementation targets. In such an implementation,
1685
1685
the trait type and ` for ` after ` impl ` are omitted. Such implementations are
1686
1686
limited to nominal types (enums, structs), and the implementation must appear
1687
- in the same module or a sub-module as the ` self ` type.
1687
+ in the same module or a sub-module as the ` self ` type:
1688
+
1689
+ ```
1690
+ struct Point {x: int, y: int}
1691
+
1692
+ impl Point {
1693
+ fn log(&self) {
1694
+ println!("Point is at ({}, {})", self.x, self.y);
1695
+ }
1696
+ }
1697
+
1698
+ let my_point = Point {x: 10, y:11};
1699
+ my_point.log();
1700
+ ```
1688
1701
1689
1702
When a trait _ is_ specified in an ` impl ` , all methods declared as part of the
1690
1703
trait must be implemented, with matching types and type parameter counts.
You can’t perform that action at this time.
0 commit comments