@@ -2062,7 +2062,7 @@ extern crate collections;
2062
2062
type Set<T> = collections::HashMap<T, ()>;
2063
2063
2064
2064
struct Stack<T> {
2065
- elements: ~[T]
2065
+ elements: Vec<T>
2066
2066
}
2067
2067
2068
2068
enum Option<T> {
@@ -2320,7 +2320,7 @@ trait Seq<T> {
2320
2320
fn length(&self) -> uint;
2321
2321
}
2322
2322
2323
- impl<T> Seq<T> for ~[T] {
2323
+ impl<T> Seq<T> for Vec<T> {
2324
2324
fn length(&self) -> uint { self.len() }
2325
2325
}
2326
2326
~~~~
@@ -2392,7 +2392,7 @@ generic types.
2392
2392
2393
2393
~~~~
2394
2394
# trait Printable { fn print(&self); }
2395
- fn print_all<T: Printable>(printable_things: ~[T] ) {
2395
+ fn print_all<T: Printable>(printable_things: Vec<T> ) {
2396
2396
for thing in printable_things.iter() {
2397
2397
thing.print();
2398
2398
}
@@ -2410,10 +2410,10 @@ as in this version of `print_all` that copies elements.
2410
2410
2411
2411
~~~
2412
2412
# trait Printable { fn print(&self); }
2413
- fn print_all<T: Printable + Clone>(printable_things: ~[T] ) {
2413
+ fn print_all<T: Printable + Clone>(printable_things: Vec<T> ) {
2414
2414
let mut i = 0;
2415
2415
while i < printable_things.len() {
2416
- let copy_of_thing = printable_things[i] .clone();
2416
+ let copy_of_thing = printable_things.get(i) .clone();
2417
2417
copy_of_thing.print();
2418
2418
i += 1;
2419
2419
}
@@ -2438,11 +2438,11 @@ However, consider this function:
2438
2438
# fn new_circle() -> int { 1 }
2439
2439
trait Drawable { fn draw(&self); }
2440
2440
2441
- fn draw_all<T: Drawable>(shapes: ~[T] ) {
2441
+ fn draw_all<T: Drawable>(shapes: Vec<T> ) {
2442
2442
for shape in shapes.iter() { shape.draw(); }
2443
2443
}
2444
2444
# let c: Circle = new_circle();
2445
- # draw_all(~ [c]);
2445
+ # draw_all(vec! [c]);
2446
2446
~~~~
2447
2447
2448
2448
You can call that on a vector of circles, or a vector of rectangles
@@ -2742,9 +2742,9 @@ mod farm {
2742
2742
# pub type Chicken = int;
2743
2743
# struct Human(int);
2744
2744
# impl Human { pub fn rest(&self) { } }
2745
- # pub fn make_me_a_farm() -> Farm { Farm { chickens: ~ [], farmer: Human(0) } }
2745
+ # pub fn make_me_a_farm() -> Farm { Farm { chickens: vec! [], farmer: Human(0) } }
2746
2746
pub struct Farm {
2747
- chickens: ~[ Chicken] ,
2747
+ chickens: Vec< Chicken> ,
2748
2748
pub farmer: Human
2749
2749
}
2750
2750
0 commit comments