Skip to content

Hunted down and deleted all remaining deprecated owned vectors from docs #14553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/doc/complement-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ To return a Borrowed String Slice (&str) use the str helper function
~~~
use std::str;

let bytes = ~[104u8,105u8];
let x: Option<&str> = str::from_utf8(bytes);
let y: &str = x.unwrap();
let bytes = &[104u8,105u8];
let x: &str = str::from_utf8(bytes).unwrap();
~~~

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

~~~
let u: ~[u32] = ~[0, 1, 2];
let u: Vec<u32> = vec![0, 1, 2];
let v: &[u32] = &[0, 1, 2, 3];
let w: [u32, .. 5] = [0, 1, 2, 3, 4];

Expand All @@ -148,7 +147,7 @@ println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
Use the [`iter`](../std/vec/trait.ImmutableVector.html#tymethod.iter) method.

~~~
let values: ~[int] = ~[1, 2, 3, 4, 5];
let values: Vec<int> = vec![1, 2, 3, 4, 5];
for value in values.iter() { // value: &int
println!("{}", *value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ To take as an argument a fragment of Rust code, write `$` followed by a name
`foo`.)
* `expr` (an expression. Examples: `2 + 2`; `if true then { 1 } else { 2 }`;
`f(42)`.)
* `ty` (a type. Examples: `int`, `~[(char, String)]`, `&T`.)
* `ty` (a type. Examples: `int`, `Vec<(char, String)>`, `&T`.)
* `pat` (a pattern, usually appearing in a `match` or on the left-hand side of
a declaration. Examples: `Some(t)`; `(17, 'a')`; `_`.)
* `block` (a sequence of actions. Example: `{ log(error, "hi"); return 12; }`)
Expand Down
30 changes: 17 additions & 13 deletions src/doc/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ Typically, tasks do not share memory but instead communicate amongst each other

```
fn main() {
let numbers = ~[1,2,3];
let numbers = vec![1,2,3];

let (tx, rx) = channel();
tx.send(numbers);

spawn(proc() {
let numbers = rx.recv();
println!("{}", numbers[0]);
println!("{}", *numbers.get(0));
})
}
```
Expand Down Expand Up @@ -237,26 +237,26 @@ try to modify the previous example to continue using the variable `numbers`:

```ignore
fn main() {
let numbers = ~[1,2,3];
let numbers = vec![1,2,3];

let (tx, rx) = channel();
tx.send(numbers);

spawn(proc() {
let numbers = rx.recv();
println!("{}", numbers[0]);
println!("{}", numbers.get(0));
});

// Try to print a number from the original task
println!("{}", numbers[0]);
println!("{}", *numbers.get(0));
}
```

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

```notrust
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
concurrency.rs:12 println!("{}", numbers[0]);
concurrency.rs:12 println!("{}", numbers.get(0));
^~~~~~~
```

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

```
fn main() {
let numbers = ~[1,2,3];
let numbers = vec![1,2,3];

for num in range(0, 3) {
let (tx, rx) = channel();
Expand All @@ -276,7 +276,7 @@ fn main() {

spawn(proc() {
let numbers = rx.recv();
println!("{:d}", numbers[num as uint]);
println!("{:d}", *numbers.get(num as uint));
})
}
}
Expand All @@ -301,7 +301,7 @@ extern crate sync;
use sync::Arc;

fn main() {
let numbers = ~[1,2,3];
let numbers = vec![1,2,3];
let numbers = Arc::new(numbers);

for num in range(0, 3) {
Expand All @@ -310,7 +310,7 @@ fn main() {

spawn(proc() {
let numbers = rx.recv();
println!("{:d}", numbers[num as uint]);
println!("{:d}", *numbers.get(num as uint));
})
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ extern crate sync;
use sync::{Arc, Mutex};

fn main() {
let numbers = ~[1,2,3];
let numbers = vec![1,2,3];
let numbers_lock = Arc::new(Mutex::new(numbers));

for num in range(0, 3) {
Expand All @@ -360,9 +360,13 @@ fn main() {

// Take the lock, along with exclusive access to the underlying array
let mut numbers = numbers_lock.lock();
numbers[num as uint] += 1;

println!("{}", numbers[num as uint]);
// This is ugly for now, but will be replaced by
// `numbers[num as uint] += 1` in the near future.
// See: https://github.com/mozilla/rust/issues/6515
*numbers.get_mut(num as uint) = *numbers.get_mut(num as uint) + 1;

println!("{}", *numbers.get(num as uint));

// When `numbers` goes out of scope the lock is dropped
})
Expand Down
20 changes: 10 additions & 10 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ fn main() {
// Equivalent to 'std::iter::range_step(0, 10, 2);'
range_step(0, 10, 2);

// Equivalent to 'foo(~[std::option::Some(1.0), std::option::None]);'
foo(~[Some(1.0), None]);
// Equivalent to 'foo(vec![std::option::Some(1.0), std::option::None]);'
foo(vec![Some(1.0), None]);
}
~~~~

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

~~~~
// Declares an extern fn, the ABI defaults to "C"
extern fn new_vec() -> ~[int] { ~[] }
extern fn new_int() -> int { 0 }

// Declares an extern fn with "stdcall" ABI
extern "stdcall" fn new_vec_stdcall() -> ~[int] { ~[] }
extern "stdcall" fn new_int_stdcall() -> int { 0 }
~~~~

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

~~~~
# extern fn new_vec() -> ~[int] { ~[] }
let fptr: extern "C" fn() -> ~[int] = new_vec;
# extern fn new_int() -> int { 0 }
let fptr: extern "C" fn() -> int = new_int;
~~~~

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

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

Expand Down
18 changes: 9 additions & 9 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ extern crate collections;
type Set<T> = collections::HashMap<T, ()>;

struct Stack<T> {
elements: ~[T]
elements: Vec<T>
}

enum Option<T> {
Expand Down Expand Up @@ -2320,7 +2320,7 @@ trait Seq<T> {
fn length(&self) -> uint;
}

impl<T> Seq<T> for ~[T] {
impl<T> Seq<T> for Vec<T> {
fn length(&self) -> uint { self.len() }
}
~~~~
Expand Down Expand Up @@ -2392,7 +2392,7 @@ generic types.

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

~~~
# trait Printable { fn print(&self); }
fn print_all<T: Printable + Clone>(printable_things: ~[T]) {
fn print_all<T: Printable + Clone>(printable_things: Vec<T>) {
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;
}
Expand All @@ -2438,11 +2438,11 @@ However, consider this function:
# fn new_circle() -> int { 1 }
trait Drawable { fn draw(&self); }

fn draw_all<T: Drawable>(shapes: ~[T]) {
fn draw_all<T: Drawable>(shapes: Vec<T>) {
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
Expand Down Expand Up @@ -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<Chicken>,
pub farmer: Human
}

Expand Down