Skip to content

Commit 4ce51a8

Browse files
committed
---
yaml --- r: 22635 b: refs/heads/master c: ac9cf98 h: refs/heads/master i: 22633: aa9eae3 22631: 1addea0 v: v3
1 parent f3a39ab commit 4ce51a8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0f34144be308d28260d2496104ad06c2cb9cf5c3
2+
refs/heads/master: ac9cf98564cc394672cd9a96a02093569951027c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/tutorial.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,22 +2504,33 @@ needed because it could also, for example, specify an implementation
25042504
of `seq<int>`—the `of` clause *refers* to a type, rather than defining
25052505
one.
25062506

2507-
Note that functions do not explicitly have the type parameters that
2508-
are provided by the iface. It will cause a compile-time error if you
2509-
include them in the iface or impl.
2507+
The type parameters bound by an iface are in scope in each of the
2508+
method declarations. So, re-declaring the type parameter
2509+
`T` as an explicit type parameter for `len` -- in either the iface or
2510+
the impl -- would be a compile-time error.
25102511

2511-
## Use of the type `self` in interfaces
2512+
## The `self` type in interfaces
25122513

2513-
Interfaces may use `self` as a type where the implementation uses its
2514-
own type. This defines an interface for testing equality of a type with
2515-
itself:
2514+
In an interface, `self` is a special type that you can think of as a
2515+
type parameter. An implementation of the interface for any given type
2516+
`T` replaces the `self` type parameter with `T`. The following
2517+
interface describes types that support an equality operation:
25162518

25172519
~~~~
25182520
iface eq {
25192521
fn equals(other: self) -> bool;
25202522
}
25212523
~~~~
25222524

2525+
In an implementation for type `int`, the `equals` method takes an
2526+
`int` argument:
2527+
2528+
~~~~
2529+
impl of eq for int {
2530+
fn equals(other: int) { other == self }
2531+
}
2532+
~~~~
2533+
25232534
## Casting to an interface type
25242535

25252536
The above allows us to define functions that polymorphically act on

0 commit comments

Comments
 (0)