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