@@ -1006,12 +1006,12 @@ declared, in an angle-bracket-enclosed, comma-separated list following
1006
1006
the function name.
1007
1007
1008
1008
~~~~
1009
- fn iter<T>(seq: [T], f: fn(T)) {
1009
+ fn iter<T>(seq: ~ [T], f: fn(T)) {
1010
1010
for seq.each {|elt| f(elt); }
1011
1011
}
1012
- fn map<T, U>(seq: [T], f: fn(T) -> U) -> [U] {
1013
- let mut acc = [];
1014
- for seq.each {|elt| acc += [ f(elt)] ; }
1012
+ fn map<T, U>(seq: ~ [T], f: fn(T) -> U) -> ~ [U] {
1013
+ let mut acc = ~ [];
1014
+ for seq.each {|elt| vec::push( acc, f(elt)) ; }
1015
1015
acc
1016
1016
}
1017
1017
~~~~
@@ -1048,14 +1048,14 @@ same as any other Rust function, except that they are prepended with the
1048
1048
` extern ` keyword.
1049
1049
1050
1050
~~~
1051
- extern fn new_vec() -> [int] { [] }
1051
+ extern fn new_vec() -> ~ [int] { ~ [] }
1052
1052
~~~
1053
1053
1054
1054
Extern functions may not be called from Rust code, but their value
1055
1055
may be taken as an unsafe ` u8 ` pointer.
1056
1056
1057
1057
~~~
1058
- # extern fn new_vec() -> [int] { [] }
1058
+ # extern fn new_vec() -> ~ [int] { ~ [] }
1059
1059
let fptr: *u8 = new_vec;
1060
1060
~~~
1061
1061
@@ -1289,7 +1289,7 @@ specified, after the `impl` keyword.
1289
1289
~~~~
1290
1290
# iface seq<T> { }
1291
1291
1292
- impl <T> of seq<T> for [T] {
1292
+ impl <T> of seq<T> for ~ [T] {
1293
1293
/* ... */
1294
1294
}
1295
1295
impl of seq<bool> for u32 {
@@ -1615,9 +1615,9 @@ indicate that the elements of the resulting vector may be mutated.
1615
1615
When no mutability is specified, the vector is immutable.
1616
1616
1617
1617
~~~~
1618
- [1, 2, 3, 4];
1619
- ["a", "b", "c", "d"];
1620
- [mut 0u8, 0u8, 0u8, 0u8];
1618
+ ~ [1, 2, 3, 4];
1619
+ ~ ["a", "b", "c", "d"];
1620
+ ~ [mut 0u8, 0u8, 0u8, 0u8];
1621
1621
~~~~
1622
1622
1623
1623
### Index expressions
@@ -1640,9 +1640,9 @@ task in a _failing state_.
1640
1640
# task::unsupervise(buildr);
1641
1641
# task::run(buildr) {||
1642
1642
1643
- [1, 2, 3, 4][0];
1644
- [mut 'x', 'y'][1] = 'z';
1645
- ["a", "b"][10]; // fails
1643
+ (~ [1, 2, 3, 4]) [0];
1644
+ (~ [mut 'x', 'y']) [1] = 'z';
1645
+ (~ ["a", "b"]) [10]; // fails
1646
1646
1647
1647
# }
1648
1648
~~~~
@@ -1760,10 +1760,10 @@ is unsupported and will fail to compile.
1760
1760
An example of an ` as ` expression:
1761
1761
1762
1762
~~~~
1763
- # fn sum(v: [float]) -> float { 0.0 }
1764
- # fn len(v: [float]) -> int { 0 }
1763
+ # fn sum(v: ~ [float]) -> float { 0.0 }
1764
+ # fn len(v: ~ [float]) -> int { 0 }
1765
1765
1766
- fn avg(v: [float]) -> float {
1766
+ fn avg(v: ~ [float]) -> float {
1767
1767
let sum: float = sum(v);
1768
1768
let sz: float = len(v) as float;
1769
1769
ret sum / sz;
@@ -1794,8 +1794,8 @@ expression. No allocation or destruction is entailed.
1794
1794
An example of three different move expressions:
1795
1795
1796
1796
~~~~~~~~
1797
- # let mut x = [mut 0];
1798
- # let a = [mut 0];
1797
+ # let mut x = ~ [mut 0];
1798
+ # let a = ~ [mut 0];
1799
1799
# let b = 0;
1800
1800
# let y = {mut z: 0};
1801
1801
# let c = 0;
@@ -1823,8 +1823,8 @@ expression. No allocation or destruction is entailed.
1823
1823
An example of three different swap expressions:
1824
1824
1825
1825
~~~~~~~~
1826
- # let mut x = [mut 0];
1827
- # let mut a = [mut 0];
1826
+ # let mut x = ~ [mut 0];
1827
+ # let mut a = ~ [mut 0];
1828
1828
# let i = 0;
1829
1829
# let y = {mut z: 0};
1830
1830
# let b = {mut c: 0};
@@ -1924,11 +1924,11 @@ argument to a function to be copied and passed by value.
1924
1924
An example of a copy expression:
1925
1925
1926
1926
~~~~
1927
- fn mutate(vec: [mut int]) {
1927
+ fn mutate(vec: ~ [mut int]) {
1928
1928
vec[0] = 10;
1929
1929
}
1930
1930
1931
- let v = [mut 1,2,3];
1931
+ let v = ~ [mut 1,2,3];
1932
1932
1933
1933
mutate(copy v); // Pass a copy
1934
1934
@@ -2067,7 +2067,7 @@ An example a for loop:
2067
2067
# fn bar(f: foo) { }
2068
2068
# let a = 0, b = 0, c = 0;
2069
2069
2070
- let v: [foo] = [a, b, c];
2070
+ let v: ~ [foo] = ~ [a, b, c];
2071
2071
2072
2072
for v.each {|e|
2073
2073
bar(e);
@@ -2272,12 +2272,12 @@ the `note` to the internal logging diagnostic buffer.
2272
2272
An example of a ` note ` expression:
2273
2273
2274
2274
~~~~ {.xfail-test}
2275
- fn read_file_lines(path: str) -> [str] {
2275
+ fn read_file_lines(path: str) -> ~ [str] {
2276
2276
note path;
2277
2277
let r: [str];
2278
2278
let f: file = open_read(path);
2279
2279
lines(f) {|s|
2280
- r += [s];
2280
+ r += ~ [s];
2281
2281
}
2282
2282
ret r;
2283
2283
}
@@ -2707,7 +2707,7 @@ the kind of its member type, as with other simple structural types.
2707
2707
An example of a vector type and its use:
2708
2708
2709
2709
~~~~
2710
- let v: [int] = [7, 5, 3];
2710
+ let v: ~ [int] = ~ [7, 5, 3];
2711
2711
let i: int = v[2];
2712
2712
assert (i == 3);
2713
2713
~~~~
@@ -2719,8 +2719,8 @@ vector:
2719
2719
2720
2720
2721
2721
~~~~
2722
- let mut v: [int] = [1, 2, 3];
2723
- v += [4, 5, 6];
2722
+ let mut v: ~ [int] = ~ [1, 2, 3];
2723
+ v += ~ [4, 5, 6];
2724
2724
~~~~
2725
2725
2726
2726
Normal vector concatenation causes the allocation of a fresh vector to hold
0 commit comments