From ac9cf98564cc394672cd9a96a02093569951027c Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 19 Jul 2012 17:56:30 -0700 Subject: [PATCH] Edit for style --- doc/tutorial.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 569538fc948..ef3004f8cbe 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2504,15 +2504,17 @@ needed because it could also, for example, specify an implementation of `seq`—the `of` clause *refers* to a type, rather than defining one. -Note that functions do not explicitly have the type parameters that -are provided by the iface. It will cause a compile-time error if you -include them in the iface or impl. +The type parameters bound by an iface are in scope in each of the +method declarations. So, re-declaring the type parameter +`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 -own type. This defines an interface for testing equality of a type with -itself: +In an interface, `self` is a special type that you can think of as a +type parameter. An implementation of the interface for any given type +`T` replaces the `self` type parameter with `T`. The following +interface describes types that support an equality operation: ~~~~ 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 The above allows us to define functions that polymorphically act on