Skip to content

Commit

Permalink
auto merge of rust-lang#19172 : alfie/rust/impl-traitless, r=stevekla…
Browse files Browse the repository at this point in the history
…bnik

An example of how implementations work without traits would be handy
  • Loading branch information
bors committed Nov 25, 2014
2 parents f6cb58c + 93ba558 commit 2264049
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,20 @@ methods in such an implementation can only be used as direct calls on the
values of the type that the implementation targets. In such an implementation,
the trait type and `for` after `impl` are omitted. Such implementations are
limited to nominal types (enums, structs), and the implementation must appear
in the same module or a sub-module as the `self` type.
in the same module or a sub-module as the `self` type:

```
struct Point {x: int, y: int}
impl Point {
fn log(&self) {
println!("Point is at ({}, {})", self.x, self.y);
}
}
let my_point = Point {x: 10, y:11};
my_point.log();
```

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

0 comments on commit 2264049

Please sign in to comment.