Skip to content

Commit c3825cb

Browse files
committed
Remove deprecated owned vector from intro.
1 parent 0033a8b commit c3825cb

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/doc/intro.md

Lines changed: 17 additions & 13 deletions
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
})

0 commit comments

Comments
 (0)