@@ -2504,22 +2504,33 @@ needed because it could also, for example, specify an implementation
2504
2504
of ` seq<int> ` —the ` of ` clause * refers* to a type, rather than defining
2505
2505
one.
2506
2506
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.
2510
2511
2511
- ## Use of the type ` self ` in interfaces
2512
+ ## The ` self ` type in interfaces
2512
2513
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:
2516
2518
2517
2519
~~~~
2518
2520
iface eq {
2519
2521
fn equals(other: self) -> bool;
2520
2522
}
2521
2523
~~~~
2522
2524
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
+
2523
2534
## Casting to an interface type
2524
2535
2525
2536
The above allows us to define functions that polymorphically act on
0 commit comments