From 1959925e514d9ecd5149435a3530dbdf0191f117 Mon Sep 17 00:00:00 2001 From: Jonathan Reem Date: Fri, 30 May 2014 19:19:52 -0700 Subject: [PATCH] Remove deprecated owned vector from tutorial. --- src/doc/tutorial.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index a22256650b854..8a759cf798006 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -2062,7 +2062,7 @@ extern crate collections; type Set = collections::HashMap; struct Stack { - elements: ~[T] + elements: Vec } enum Option { @@ -2320,7 +2320,7 @@ trait Seq { fn length(&self) -> uint; } -impl Seq for ~[T] { +impl Seq for Vec { fn length(&self) -> uint { self.len() } } ~~~~ @@ -2392,7 +2392,7 @@ generic types. ~~~~ # trait Printable { fn print(&self); } -fn print_all(printable_things: ~[T]) { +fn print_all(printable_things: Vec) { for thing in printable_things.iter() { thing.print(); } @@ -2410,10 +2410,10 @@ as in this version of `print_all` that copies elements. ~~~ # trait Printable { fn print(&self); } -fn print_all(printable_things: ~[T]) { +fn print_all(printable_things: Vec) { 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; } @@ -2438,11 +2438,11 @@ However, consider this function: # fn new_circle() -> int { 1 } trait Drawable { fn draw(&self); } -fn draw_all(shapes: ~[T]) { +fn draw_all(shapes: Vec) { 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 @@ -2742,9 +2742,9 @@ mod farm { # 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, pub farmer: Human }