summary refs log tree commit diff
path: root/src/doc/reference.md
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-25 11:46:39 +0000
committerbors <bors@rust-lang.org>2014-11-25 11:46:39 +0000
commit2264049577e1d64a2a863a9b9f2b7d94f6b90e15 (patch)
tree46d2cdd232d3d6e285e96049fa7e32fb2105586b /src/doc/reference.md
parentf6cb58caeedf509cc80dd376bbb2541a0446046b (diff)
parent93ba558588c3c3c406d2ba923794550567c66bed (diff)
downloadrust-2264049577e1d64a2a863a9b9f2b7d94f6b90e15.tar.gz
rust-2264049577e1d64a2a863a9b9f2b7d94f6b90e15.zip
auto merge of #19172 : alfie/rust/impl-traitless, r=steveklabnik
An example of how implementations work without traits would be handy
Diffstat (limited to 'src/doc/reference.md')
-rw-r--r--src/doc/reference.md15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md
index a62f8bf9601..f53d083ee06 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -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.