@@ -1909,7 +1909,7 @@ struct TimeBomb {
1909
1909
explosivity: uint
1910
1910
}
1911
1911
1912
- impl TimeBomb : Drop {
1912
+ impl Drop for TimeBomb {
1913
1913
fn finalize(&self) {
1914
1914
for iter::repeat(self.explosivity) {
1915
1915
io::println("blam!");
@@ -1943,11 +1943,11 @@ and `&str`.
1943
1943
1944
1944
~~~~
1945
1945
# trait Printable { fn print(&self); }
1946
- impl int: Printable {
1946
+ impl Printable for int {
1947
1947
fn print(&self) { io::println(fmt!("%d", *self)) }
1948
1948
}
1949
1949
1950
- impl &str: Printable {
1950
+ impl Printable for &str {
1951
1951
fn print(&self) { io::println(*self) }
1952
1952
}
1953
1953
@@ -1966,7 +1966,7 @@ trait Seq<T> {
1966
1966
fn iter(&self, b: fn(v: &T));
1967
1967
}
1968
1968
1969
- impl<T> ~[T]: Seq<T> {
1969
+ impl<T> Seq<T> for ~[T] {
1970
1970
fn len(&self) -> uint { vec::len(*self) }
1971
1971
fn iter(&self, b: fn(v: &T)) {
1972
1972
for vec::each(*self) |elt| { b(elt); }
@@ -1978,7 +1978,7 @@ The implementation has to explicitly declare the type parameter that
1978
1978
it binds, ` T ` , before using it to specify its trait type. Rust
1979
1979
requires this declaration because the ` impl ` could also, for example,
1980
1980
specify an implementation of ` Seq<int> ` . The trait type (appearing
1981
- after the colon in the ` impl ` ) * refers* to a type, rather than
1981
+ between ` impl ` and ` for ` ) * refers* to a type, rather than
1982
1982
defining one.
1983
1983
1984
1984
The type parameters bound by a trait are in scope in each of the
@@ -2000,7 +2000,7 @@ trait Eq {
2000
2000
}
2001
2001
2002
2002
// In an impl, `self` refers just to the value of the receiver
2003
- impl int: Eq {
2003
+ impl Eq for int {
2004
2004
fn equals(&self, other: &int) -> bool { *other == *self }
2005
2005
}
2006
2006
~~~~
@@ -2021,10 +2021,10 @@ trait Shape { static fn new(area: float) -> Self; }
2021
2021
struct Circle { radius: float }
2022
2022
struct Square { length: float }
2023
2023
2024
- impl Circle: Shape {
2024
+ impl Shape for Circle {
2025
2025
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
2026
2026
}
2027
- impl Square: Shape {
2027
+ impl Shape for Square {
2028
2028
static fn new(area: float) -> Square { Square { length: sqrt(area) } }
2029
2029
}
2030
2030
@@ -2084,7 +2084,7 @@ However, consider this function:
2084
2084
2085
2085
~~~~
2086
2086
# type Circle = int; type Rectangle = int;
2087
- # impl int: Drawable { fn draw(&self) {} }
2087
+ # impl Drawable for int { fn draw(&self) {} }
2088
2088
# fn new_circle() -> int { 1 }
2089
2089
trait Drawable { fn draw(&self); }
2090
2090
@@ -2120,9 +2120,8 @@ value to an object:
2120
2120
# fn new_rectangle() -> Rectangle { true }
2121
2121
# fn draw_all(shapes: &[@Drawable]) {}
2122
2122
2123
- impl Circle: Drawable { fn draw(&self) { ... } }
2124
-
2125
- impl Rectangle: Drawable { fn draw(&self) { ... } }
2123
+ impl Drawable for Circle { fn draw(&self) { ... } }
2124
+ impl Drawable for Rectangle { fn draw(&self) { ... } }
2126
2125
2127
2126
let c: @Circle = @new_circle();
2128
2127
let r: @Rectangle = @new_rectangle();
@@ -2140,7 +2139,7 @@ for example, an `@Circle` may not be cast to an `~Drawable`.
2140
2139
~~~
2141
2140
# type Circle = int; type Rectangle = int;
2142
2141
# trait Drawable { fn draw(&self); }
2143
- # impl int: Drawable { fn draw(&self) {} }
2142
+ # impl Drawable for int { fn draw(&self) {} }
2144
2143
# fn new_circle() -> int { 1 }
2145
2144
# fn new_rectangle() -> int { 2 }
2146
2145
// A managed object
@@ -2180,10 +2179,10 @@ Now, we can implement `Circle` on a type only if we also implement `Shape`.
2180
2179
# use float::sqrt;
2181
2180
# fn square(x: float) -> float { x * x }
2182
2181
struct CircleStruct { center: Point, radius: float }
2183
- impl CircleStruct: Circle {
2182
+ impl Circle for CircleStruct {
2184
2183
fn radius(&self) -> float { sqrt(self.area() / pi) }
2185
2184
}
2186
- impl CircleStruct: Shape {
2185
+ impl Shape for CircleStruct {
2187
2186
fn area(&self) -> float { pi * square(self.radius) }
2188
2187
}
2189
2188
~~~~
@@ -2215,8 +2214,8 @@ Likewise, supertrait methods may also be called on trait objects.
2215
2214
# use float::sqrt;
2216
2215
# struct Point { x: float, y: float }
2217
2216
# struct CircleStruct { center: Point, radius: float }
2218
- # impl CircleStruct: Circle { fn radius(&self) -> float { sqrt(self.area() / pi) } }
2219
- # impl CircleStruct: Shape { fn area(&self) -> float { pi * square(self.radius) } }
2217
+ # impl Circle for CircleStruct { fn radius(&self) -> float { sqrt(self.area() / pi) } }
2218
+ # impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } }
2220
2219
2221
2220
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
2222
2221
let mycircle: Circle = concrete as @Circle;
0 commit comments