Skip to content

Commit 1959925

Browse files
committed
Remove deprecated owned vector from tutorial.
1 parent 66ee71a commit 1959925

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/doc/tutorial.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ extern crate collections;
20622062
type Set<T> = collections::HashMap<T, ()>;
20632063
20642064
struct Stack<T> {
2065-
elements: ~[T]
2065+
elements: Vec<T>
20662066
}
20672067
20682068
enum Option<T> {
@@ -2320,7 +2320,7 @@ trait Seq<T> {
23202320
fn length(&self) -> uint;
23212321
}
23222322
2323-
impl<T> Seq<T> for ~[T] {
2323+
impl<T> Seq<T> for Vec<T> {
23242324
fn length(&self) -> uint { self.len() }
23252325
}
23262326
~~~~
@@ -2392,7 +2392,7 @@ generic types.
23922392

23932393
~~~~
23942394
# trait Printable { fn print(&self); }
2395-
fn print_all<T: Printable>(printable_things: ~[T]) {
2395+
fn print_all<T: Printable>(printable_things: Vec<T>) {
23962396
for thing in printable_things.iter() {
23972397
thing.print();
23982398
}
@@ -2410,10 +2410,10 @@ as in this version of `print_all` that copies elements.
24102410

24112411
~~~
24122412
# 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>) {
24142414
let mut i = 0;
24152415
while i < printable_things.len() {
2416-
let copy_of_thing = printable_things[i].clone();
2416+
let copy_of_thing = printable_things.get(i).clone();
24172417
copy_of_thing.print();
24182418
i += 1;
24192419
}
@@ -2438,11 +2438,11 @@ However, consider this function:
24382438
# fn new_circle() -> int { 1 }
24392439
trait Drawable { fn draw(&self); }
24402440
2441-
fn draw_all<T: Drawable>(shapes: ~[T]) {
2441+
fn draw_all<T: Drawable>(shapes: Vec<T>) {
24422442
for shape in shapes.iter() { shape.draw(); }
24432443
}
24442444
# let c: Circle = new_circle();
2445-
# draw_all(~[c]);
2445+
# draw_all(vec![c]);
24462446
~~~~
24472447

24482448
You can call that on a vector of circles, or a vector of rectangles
@@ -2742,9 +2742,9 @@ mod farm {
27422742
# pub type Chicken = int;
27432743
# struct Human(int);
27442744
# 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) } }
27462746
pub struct Farm {
2747-
chickens: ~[Chicken],
2747+
chickens: Vec<Chicken>,
27482748
pub farmer: Human
27492749
}
27502750

0 commit comments

Comments
 (0)