@@ -74,7 +74,7 @@ Here's a parallel game of rock, paper, scissors to whet your appetite.
74
74
~~~~
75
75
use std;
76
76
77
- import comm::{ listen, methods} ;
77
+ import comm::listen;
78
78
import task::spawn;
79
79
import iter::repeat;
80
80
import rand::{seeded_rng, seed};
@@ -2440,10 +2440,10 @@ is used. This defines implementations of `to_str` for the `int` and
2440
2440
2441
2441
~~~~
2442
2442
# trait to_str { fn to_str() -> ~str; }
2443
- impl of to_str for int {
2443
+ impl int: to_str {
2444
2444
fn to_str() -> ~str { int::to_str(self, 10u) }
2445
2445
}
2446
- impl of to_str for ~str {
2446
+ impl ~str: to_str {
2447
2447
fn to_str() -> ~str { self }
2448
2448
}
2449
2449
~~~~
@@ -2454,22 +2454,6 @@ static overloading—when the Rust compiler sees the `to_str` method
2454
2454
call, it looks for an implementation that matches the type with a
2455
2455
method that matches the name, and simply calls that.
2456
2456
2457
- ## Scoping
2458
-
2459
- Implementations are not globally visible. Resolving a method to an
2460
- implementation requires that implementation to be in scope. You can
2461
- import and export implementations using the name of the trait they
2462
- implement (multiple implementations with the same name can be in scope
2463
- without problems). Or you can give them an explicit name if you
2464
- prefer, using this syntax:
2465
-
2466
- ~~~~
2467
- # trait to_str { fn to_str() -> ~str; }
2468
- impl nil_to_str of to_str for () {
2469
- fn to_str() -> ~str { ~"()" }
2470
- }
2471
- ~~~~
2472
-
2473
2457
## Bounded type parameters
2474
2458
2475
2459
The useful thing about value polymorphism is that it does not have to
@@ -2510,7 +2494,7 @@ trait seq<T> {
2510
2494
fn len() -> uint;
2511
2495
fn iter(fn(T));
2512
2496
}
2513
- impl <T> of seq<T> for ~[T] {
2497
+ impl<T> ~[T]: seq<T> {
2514
2498
fn len() -> uint { vec::len(self) }
2515
2499
fn iter(b: fn(T)) {
2516
2500
for self.each |elt| { b(elt); }
@@ -2541,7 +2525,7 @@ trait eq {
2541
2525
fn equals(&&other: self) -> bool;
2542
2526
}
2543
2527
2544
- impl of eq for int {
2528
+ impl int: eq {
2545
2529
fn equals(&&other: int) -> bool { other == self }
2546
2530
}
2547
2531
~~~~
@@ -2558,7 +2542,7 @@ However, consider this function:
2558
2542
~~~~
2559
2543
# type circle = int; type rectangle = int;
2560
2544
# trait drawable { fn draw(); }
2561
- # impl of drawable for int { fn draw() {} }
2545
+ # impl int: drawable { fn draw() {} }
2562
2546
# fn new_circle() -> int { 1 }
2563
2547
fn draw_all<T: drawable>(shapes: ~[T]) {
2564
2548
for shapes.each |shape| { shape.draw(); }
@@ -2595,7 +2579,7 @@ to a trait type:
2595
2579
~~~~
2596
2580
# type circle = int; type rectangle = int;
2597
2581
# trait drawable { fn draw(); }
2598
- # impl of drawable for int { fn draw() {} }
2582
+ # impl int: drawable { fn draw() {} }
2599
2583
# fn new_circle() -> int { 1 }
2600
2584
# fn new_rectangle() -> int { 2 }
2601
2585
# fn draw_all(shapes: ~[drawable]) {}
@@ -2909,7 +2893,7 @@ in parallel. We might write something like:
2909
2893
2910
2894
~~~~
2911
2895
import task::spawn;
2912
- import comm::{port, chan, methods };
2896
+ import comm::{port, chan};
2913
2897
2914
2898
let port = port();
2915
2899
let chan = port.chan();
@@ -2939,7 +2923,7 @@ once it is complete. The second line creates a channel for sending
2939
2923
integers to the port ` port ` :
2940
2924
2941
2925
~~~~
2942
- # import comm::{port, chan, methods };
2926
+ # import comm::{port, chan};
2943
2927
# let port = port::<int>();
2944
2928
let chan = port.chan();
2945
2929
~~~~
@@ -2949,7 +2933,7 @@ The next statement actually spawns the child:
2949
2933
2950
2934
~~~~
2951
2935
# import task::{spawn};
2952
- # import comm::{port, chan, methods };
2936
+ # import comm::{port, chan};
2953
2937
# fn some_expensive_computation() -> int { 42 }
2954
2938
# let port = port();
2955
2939
# let chan = port.chan();
@@ -2969,7 +2953,7 @@ some other expensive computation and then waiting for the child's result
2969
2953
to arrive on the port:
2970
2954
2971
2955
~~~~
2972
- # import comm::{port, chan, methods };
2956
+ # import comm::{port, chan};
2973
2957
# fn some_other_expensive_computation() {}
2974
2958
# let port = port::<int>();
2975
2959
# let chan = chan::<int>(port);
@@ -2991,7 +2975,7 @@ the string in response. The child terminates when `0` is received.
2991
2975
Here is the function that implements the child task:
2992
2976
2993
2977
~~~~
2994
- # import comm::{port, chan, methods };
2978
+ # import comm::{port, chan};
2995
2979
fn stringifier(from_parent: port<uint>,
2996
2980
to_parent: chan<~str>) {
2997
2981
let mut value: uint;
@@ -3015,7 +2999,7 @@ Here is the code for the parent task:
3015
2999
3016
3000
~~~~
3017
3001
# import task::{spawn_conversation};
3018
- # import comm::{chan, port, methods };
3002
+ # import comm::{chan, port};
3019
3003
# fn stringifier(from_parent: comm::port<uint>,
3020
3004
# to_parent: comm::chan<~str>) {
3021
3005
# comm::send(to_parent, ~"22");
0 commit comments