}
```
-**Note: obviously this is very simple and non-idiomatic C++.
-You wouldn't write it in practice; it is for illustrative purposes.**
+**Note: The above C++ code is deliberately simple and non-idiomatic for the purpose
+of demonstration. It is not representative of production-quality C++ code.**
This function allocates an integer on the stack,
and stores it in a variable, `i`.
spawn(proc() {
let numbers = rx.recv();
- println!("{}", *numbers.get(0));
+ println!("{}", numbers[0]);
})
}
```
spawn(proc() {
let numbers = rx.recv();
- println!("{}", numbers.get(0));
+ println!("{}", numbers[0]);
});
// Try to print a number from the original task
- println!("{}", *numbers.get(0));
+ println!("{}", numbers[0]);
}
```
-This will result an error indicating that the value is no longer in scope:
+The compiler will produce an error indicating that the value is no longer in scope:
```text
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
-concurrency.rs:12 println!("{}", numbers.get(0));
+concurrency.rs:12 println!("{}", numbers[0]);
^~~~~~~
```
spawn(proc() {
let numbers = rx.recv();
- println!("{:d}", *numbers.get(num as uint));
+ println!("{:d}", numbers[num]);
})
}
}
spawn(proc() {
let numbers = rx.recv();
- println!("{:d}", *numbers.get(num as uint));
+ println!("{:d}", (*numbers)[num as uint]);
})
}
}
// See: https://github.com/rust-lang/rust/issues/6515
*numbers.get_mut(num as uint) = *numbers.get_mut(num as uint) + 1;
- println!("{}", *numbers.get(num as uint));
+ println!("{}", (*numbers)[num as uint]);
// When `numbers` goes out of scope the lock is dropped
})