Skip to content

Commit 13ea161

Browse files
committed
manual: remove as many ~[] literals as possible.
1 parent d81d4f1 commit 13ea161

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

doc/rust.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following
908908
the function name.
909909

910910
~~~~ {.xfail-test}
911-
fn iter<T>(seq: ~[T], f: fn(T)) {
911+
fn iter<T>(seq: &[T], f: fn(T)) {
912912
for seq.each |elt| { f(elt); }
913913
}
914-
fn map<T, U>(seq: ~[T], f: fn(T) -> U) -> ~[U] {
914+
fn map<T, U>(seq: &[T], f: fn(T) -> U) -> ~[U] {
915915
let mut acc = ~[];
916916
for seq.each |elt| { acc.push(f(elt)); }
917917
acc
@@ -1608,9 +1608,9 @@ indicate that the elements of the resulting vector may be mutated.
16081608
When no mutability is specified, the vector is immutable.
16091609

16101610
~~~~
1611-
~[1, 2, 3, 4];
1612-
~["a", "b", "c", "d"];
1613-
~[mut 0u8, 0u8, 0u8, 0u8];
1611+
[1, 2, 3, 4];
1612+
["a", "b", "c", "d"];
1613+
[mut 0u8, 0u8, 0u8, 0u8];
16141614
~~~~
16151615

16161616
### Index expressions
@@ -1631,9 +1631,9 @@ task in a _failing state_.
16311631
~~~~
16321632
# do task::spawn_unlinked {
16331633
1634-
(~[1, 2, 3, 4])[0];
1635-
(~[mut 'x', 'y'])[1] = 'z';
1636-
(~["a", "b"])[10]; // fails
1634+
([1, 2, 3, 4])[0];
1635+
([mut 'x', 'y'])[1] = 'z';
1636+
(["a", "b"])[10]; // fails
16371637
16381638
# }
16391639
~~~~
@@ -1770,10 +1770,10 @@ Any other cast is unsupported and will fail to compile.
17701770
An example of an `as` expression:
17711771

17721772
~~~~
1773-
# fn sum(v: ~[float]) -> float { 0.0 }
1774-
# fn len(v: ~[float]) -> int { 0 }
1773+
# fn sum(v: &[float]) -> float { 0.0 }
1774+
# fn len(v: &[float]) -> int { 0 }
17751775
1776-
fn avg(v: ~[float]) -> float {
1776+
fn avg(v: &[float]) -> float {
17771777
let sum: float = sum(v);
17781778
let sz: float = len(v) as float;
17791779
return sum / sz;
@@ -1800,8 +1800,8 @@ No allocation or destruction is entailed.
18001800
An example of three different move expressions:
18011801

18021802
~~~~~~~~
1803-
# let mut x = ~[mut 0];
1804-
# let a = ~[mut 0];
1803+
# let mut x = &[mut 0];
1804+
# let a = &[mut 0];
18051805
# let b = 0;
18061806
# let y = {mut z: 0};
18071807
# let c = 0;
@@ -1827,8 +1827,8 @@ No allocation or destruction is entailed.
18271827
An example of three different swap expressions:
18281828

18291829
~~~~~~~~
1830-
# let mut x = ~[mut 0];
1831-
# let mut a = ~[mut 0];
1830+
# let mut x = &[mut 0];
1831+
# let mut a = &[mut 0];
18321832
# let i = 0;
18331833
# let y = {mut z: 0};
18341834
# let b = {mut c: 0};
@@ -1929,11 +1929,11 @@ the unary copy operator is typically only used to cause an argument to a functio
19291929
An example of a copy expression:
19301930

19311931
~~~~
1932-
fn mutate(vec: ~[mut int]) {
1932+
fn mutate(vec: &[mut int]) {
19331933
vec[0] = 10;
19341934
}
19351935
1936-
let v = ~[mut 1,2,3];
1936+
let v = &[mut 1,2,3];
19371937
19381938
mutate(copy v); // Pass a copy
19391939
@@ -2716,7 +2716,7 @@ In this example, the trait `Printable` occurs as a type in both the type signatu
27162716
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
27172717

27182718
~~~~~~~
2719-
fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: ~[A]) -> ~[B] {
2719+
fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: &[A]) -> ~[B] {
27202720
if xs.len() == 0 { return ~[]; }
27212721
let first: B = f(xs[0]);
27222722
let rest: ~[B] = map(f, xs.slice(1, xs.len()));

0 commit comments

Comments
 (0)