Skip to content

Commit ac9cf98

Browse files
committed
Edit for style
1 parent 0f34144 commit ac9cf98

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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)