Edit for style

This commit is contained in:
Tim Chevalier 2012-07-19 17:56:30 -07:00
parent 0f34144be3
commit ac9cf98564

View File

@ -2504,15 +2504,17 @@ needed because it could also, for example, specify an implementation
of `seq<int>`—the `of` clause *refers* to a type, rather than defining of `seq<int>`—the `of` clause *refers* to a type, rather than defining
one. one.
Note that functions do not explicitly have the type parameters that The type parameters bound by an iface are in scope in each of the
are provided by the iface. It will cause a compile-time error if you method declarations. So, re-declaring the type parameter
include them in the iface or impl. `T` as an explicit type parameter for `len` -- in either the iface or
the impl -- would be a compile-time error.
## Use of the type `self` in interfaces ## The `self` type in interfaces
Interfaces may use `self` as a type where the implementation uses its In an interface, `self` is a special type that you can think of as a
own type. This defines an interface for testing equality of a type with type parameter. An implementation of the interface for any given type
itself: `T` replaces the `self` type parameter with `T`. The following
interface describes types that support an equality operation:
~~~~ ~~~~
iface eq { iface eq {
@ -2520,6 +2522,15 @@ iface eq {
} }
~~~~ ~~~~
In an implementation for type `int`, the `equals` method takes an
`int` argument:
~~~~
impl of eq for int {
fn equals(other: int) { other == self }
}
~~~~
## Casting to an interface type ## Casting to an interface type
The above allows us to define functions that polymorphically act on The above allows us to define functions that polymorphically act on