type Set<T> = collections::HashMap<T, ()>;
struct Stack<T> {
- elements: ~[T]
+ elements: Vec<T>
}
enum Option<T> {
fn length(&self) -> uint;
}
-impl<T> Seq<T> for ~[T] {
+impl<T> Seq<T> for Vec<T> {
fn length(&self) -> uint { self.len() }
}
~~~~
~~~~
# trait Printable { fn print(&self); }
-fn print_all<T: Printable>(printable_things: ~[T]) {
+fn print_all<T: Printable>(printable_things: Vec<T>) {
for thing in printable_things.iter() {
thing.print();
}
~~~
# trait Printable { fn print(&self); }
-fn print_all<T: Printable + Clone>(printable_things: ~[T]) {
+fn print_all<T: Printable + Clone>(printable_things: Vec<T>) {
let mut i = 0;
while i < printable_things.len() {
- let copy_of_thing = printable_things[i].clone();
+ let copy_of_thing = printable_things.get(i).clone();
copy_of_thing.print();
i += 1;
}
# fn new_circle() -> int { 1 }
trait Drawable { fn draw(&self); }
-fn draw_all<T: Drawable>(shapes: ~[T]) {
+fn draw_all<T: Drawable>(shapes: Vec<T>) {
for shape in shapes.iter() { shape.draw(); }
}
# let c: Circle = new_circle();
-# draw_all(~[c]);
+# draw_all(vec![c]);
~~~~
You can call that on a vector of circles, or a vector of rectangles
# pub type Chicken = int;
# struct Human(int);
# impl Human { pub fn rest(&self) { } }
-# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], farmer: Human(0) } }
+# pub fn make_me_a_farm() -> Farm { Farm { chickens: vec![], farmer: Human(0) } }
pub struct Farm {
- chickens: ~[Chicken],
+ chickens: Vec<Chicken>,
pub farmer: Human
}