Skip to content

Commit faa7ba7

Browse files
committed
auto merge of #14553 : reem/rust/nuke-owned-vectors, r=alexcrichton
I removed all remaining deprecated owned vectors from the docs. All example tests pass.
2 parents 92c43db + 1959925 commit faa7ba7

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

src/doc/complement-cheatsheet.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ To return a Borrowed String Slice (&str) use the str helper function
5353
~~~
5454
use std::str;
5555
56-
let bytes = ~[104u8,105u8];
57-
let x: Option<&str> = str::from_utf8(bytes);
58-
let y: &str = x.unwrap();
56+
let bytes = &[104u8,105u8];
57+
let x: &str = str::from_utf8(bytes).unwrap();
5958
~~~
6059

6160
To return an Owned String use the str helper function
@@ -136,7 +135,7 @@ let index: Option<uint> = str.find_str("rand");
136135
The [`Container`](../std/container/trait.Container.html) trait provides the `len` method.
137136

138137
~~~
139-
let u: ~[u32] = ~[0, 1, 2];
138+
let u: Vec<u32> = vec![0, 1, 2];
140139
let v: &[u32] = &[0, 1, 2, 3];
141140
let w: [u32, .. 5] = [0, 1, 2, 3, 4];
142141
@@ -148,7 +147,7 @@ println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
148147
Use the [`iter`](../std/vec/trait.ImmutableVector.html#tymethod.iter) method.
149148

150149
~~~
151-
let values: ~[int] = ~[1, 2, 3, 4, 5];
150+
let values: Vec<int> = vec![1, 2, 3, 4, 5];
152151
for value in values.iter() { // value: &int
153152
println!("{}", *value);
154153
}

src/doc/guide-macros.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ To take as an argument a fragment of Rust code, write `$` followed by a name
8585
`foo`.)
8686
* `expr` (an expression. Examples: `2 + 2`; `if true then { 1 } else { 2 }`;
8787
`f(42)`.)
88-
* `ty` (a type. Examples: `int`, `~[(char, String)]`, `&T`.)
88+
* `ty` (a type. Examples: `int`, `Vec<(char, String)>`, `&T`.)
8989
* `pat` (a pattern, usually appearing in a `match` or on the left-hand side of
9090
a declaration. Examples: `Some(t)`; `(17, 'a')`; `_`.)
9191
* `block` (a sequence of actions. Example: `{ log(error, "hi"); return 12; }`)

src/doc/intro.md

+17-13
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ Typically, tasks do not share memory but instead communicate amongst each other
198198

199199
```
200200
fn main() {
201-
let numbers = ~[1,2,3];
201+
let numbers = vec![1,2,3];
202202
203203
let (tx, rx) = channel();
204204
tx.send(numbers);
205205
206206
spawn(proc() {
207207
let numbers = rx.recv();
208-
println!("{}", numbers[0]);
208+
println!("{}", *numbers.get(0));
209209
})
210210
}
211211
```
@@ -237,26 +237,26 @@ try to modify the previous example to continue using the variable `numbers`:
237237

238238
```ignore
239239
fn main() {
240-
let numbers = ~[1,2,3];
240+
let numbers = vec![1,2,3];
241241
242242
let (tx, rx) = channel();
243243
tx.send(numbers);
244244
245245
spawn(proc() {
246246
let numbers = rx.recv();
247-
println!("{}", numbers[0]);
247+
println!("{}", numbers.get(0));
248248
});
249249
250250
// Try to print a number from the original task
251-
println!("{}", numbers[0]);
251+
println!("{}", *numbers.get(0));
252252
}
253253
```
254254

255255
This will result an error indicating that the value is no longer in scope:
256256

257257
```notrust
258258
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
259-
concurrency.rs:12 println!("{}", numbers[0]);
259+
concurrency.rs:12 println!("{}", numbers.get(0));
260260
^~~~~~~
261261
```
262262

@@ -267,7 +267,7 @@ Let's see an example that uses the `clone` method to create copies of the data:
267267

268268
```
269269
fn main() {
270-
let numbers = ~[1,2,3];
270+
let numbers = vec![1,2,3];
271271
272272
for num in range(0, 3) {
273273
let (tx, rx) = channel();
@@ -276,7 +276,7 @@ fn main() {
276276
277277
spawn(proc() {
278278
let numbers = rx.recv();
279-
println!("{:d}", numbers[num as uint]);
279+
println!("{:d}", *numbers.get(num as uint));
280280
})
281281
}
282282
}
@@ -301,7 +301,7 @@ extern crate sync;
301301
use sync::Arc;
302302
303303
fn main() {
304-
let numbers = ~[1,2,3];
304+
let numbers = vec![1,2,3];
305305
let numbers = Arc::new(numbers);
306306
307307
for num in range(0, 3) {
@@ -310,7 +310,7 @@ fn main() {
310310
311311
spawn(proc() {
312312
let numbers = rx.recv();
313-
println!("{:d}", numbers[num as uint]);
313+
println!("{:d}", *numbers.get(num as uint));
314314
})
315315
}
316316
}
@@ -348,7 +348,7 @@ extern crate sync;
348348
use sync::{Arc, Mutex};
349349
350350
fn main() {
351-
let numbers = ~[1,2,3];
351+
let numbers = vec![1,2,3];
352352
let numbers_lock = Arc::new(Mutex::new(numbers));
353353
354354
for num in range(0, 3) {
@@ -360,9 +360,13 @@ fn main() {
360360
361361
// Take the lock, along with exclusive access to the underlying array
362362
let mut numbers = numbers_lock.lock();
363-
numbers[num as uint] += 1;
364363
365-
println!("{}", numbers[num as uint]);
364+
// This is ugly for now, but will be replaced by
365+
// `numbers[num as uint] += 1` in the near future.
366+
// See: https://github.com/mozilla/rust/issues/6515
367+
*numbers.get_mut(num as uint) = *numbers.get_mut(num as uint) + 1;
368+
369+
println!("{}", *numbers.get(num as uint));
366370
367371
// When `numbers` goes out of scope the lock is dropped
368372
})

src/doc/rust.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ fn main() {
886886
// Equivalent to 'std::iter::range_step(0, 10, 2);'
887887
range_step(0, 10, 2);
888888
889-
// Equivalent to 'foo(~[std::option::Some(1.0), std::option::None]);'
890-
foo(~[Some(1.0), None]);
889+
// Equivalent to 'foo(vec![std::option::Some(1.0), std::option::None]);'
890+
foo(vec![Some(1.0), None]);
891891
}
892892
~~~~
893893

@@ -995,8 +995,8 @@ the function name.
995995
fn iter<T>(seq: &[T], f: |T|) {
996996
for elt in seq.iter() { f(elt); }
997997
}
998-
fn map<T, U>(seq: &[T], f: |T| -> U) -> ~[U] {
999-
let mut acc = ~[];
998+
fn map<T, U>(seq: &[T], f: |T| -> U) -> Vec<U> {
999+
let mut acc = vec![];
10001000
for elt in seq.iter() { acc.push(f(elt)); }
10011001
acc
10021002
}
@@ -1159,19 +1159,19 @@ except that they have the `extern` modifier.
11591159

11601160
~~~~
11611161
// Declares an extern fn, the ABI defaults to "C"
1162-
extern fn new_vec() -> ~[int] { ~[] }
1162+
extern fn new_int() -> int { 0 }
11631163
11641164
// Declares an extern fn with "stdcall" ABI
1165-
extern "stdcall" fn new_vec_stdcall() -> ~[int] { ~[] }
1165+
extern "stdcall" fn new_int_stdcall() -> int { 0 }
11661166
~~~~
11671167

11681168
Unlike normal functions, extern fns have an `extern "ABI" fn()`.
11691169
This is the same type as the functions declared in an extern
11701170
block.
11711171

11721172
~~~~
1173-
# extern fn new_vec() -> ~[int] { ~[] }
1174-
let fptr: extern "C" fn() -> ~[int] = new_vec;
1173+
# extern fn new_int() -> int { 0 }
1174+
let fptr: extern "C" fn() -> int = new_int;
11751175
~~~~
11761176

11771177
Extern functions may be called directly from Rust code as Rust uses large,
@@ -1509,7 +1509,7 @@ Implementation parameters are written after the `impl` keyword.
15091509

15101510
~~~~
15111511
# trait Seq<T> { }
1512-
impl<T> Seq<T> for ~[T] {
1512+
impl<T> Seq<T> for Vec<T> {
15131513
/* ... */
15141514
}
15151515
impl Seq<bool> for u32 {
@@ -3347,7 +3347,7 @@ Such a definite-sized vector type is a first-class type, since its size is known
33473347
A vector without such a size is said to be of _indefinite_ size,
33483348
and is therefore not a _first-class_ type.
33493349
An indefinite-size vector can only be instantiated through a pointer type,
3350-
such as `&[T]` or `~[T]`.
3350+
such as `&[T]` or `Vec<T>`.
33513351
The kind of a vector type depends on the kind of its element type,
33523352
as with other simple structural types.
33533353

src/doc/tutorial.md

+9-9
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)