Skip to content

Commit 2264049

Browse files
committed
auto merge of #19172 : alfie/rust/impl-traitless, r=steveklabnik
An example of how implementations work without traits would be handy
2 parents f6cb58c + 93ba558 commit 2264049

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/doc/reference.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,20 @@ methods in such an implementation can only be used as direct calls on the
16891689
values of the type that the implementation targets. In such an implementation,
16901690
the trait type and `for` after `impl` are omitted. Such implementations are
16911691
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+
```
16931706

16941707
When a trait _is_ specified in an `impl`, all methods declared as part of the
16951708
trait must be implemented, with matching types and type parameter counts.

0 commit comments

Comments
 (0)