@@ -1502,7 +1502,7 @@ and [`core::str`]. Here are some examples.
1502
1502
# fn unwrap_crayon(c: Crayon) -> int { 0 }
1503
1503
# fn eat_crayon_wax(i: int) { }
1504
1504
# fn store_crayon_in_nasal_cavity(i: uint, c: Crayon) { }
1505
- # fn crayon_to_str(c: Crayon) -> ~ str { ~ "" }
1505
+ # fn crayon_to_str(c: Crayon) -> & str { "" }
1506
1506
1507
1507
let crayons = &[Almond, AntiqueBrass, Apricot];
1508
1508
@@ -1649,11 +1649,11 @@ callers may pass any kind of closure.
1649
1649
1650
1650
~~~~
1651
1651
fn call_twice(f: fn()) { f(); f(); }
1652
- call_twice(|| { ~ "I am an inferred stack closure"; } );
1653
- call_twice(fn&() { ~ "I am also a stack closure"; } );
1654
- call_twice(fn@() { ~ "I am a managed closure"; });
1655
- call_twice(fn~() { ~ "I am an owned closure"; });
1656
- fn bare_function() { ~ "I am a plain function"; }
1652
+ call_twice(|| { "I am an inferred stack closure"; } );
1653
+ call_twice(fn&() { "I am also a stack closure"; } );
1654
+ call_twice(fn@() { "I am a managed closure"; });
1655
+ call_twice(fn~() { "I am an owned closure"; });
1656
+ fn bare_function() { "I am a plain function"; }
1657
1657
call_twice(bare_function);
1658
1658
~~~~
1659
1659
@@ -1767,7 +1767,7 @@ And using this function to iterate over a vector:
1767
1767
# use println = io::println;
1768
1768
each(&[2, 4, 8, 5, 16], |n| {
1769
1769
if *n % 2 != 0 {
1770
- println(~ "found odd number!");
1770
+ println("found odd number!");
1771
1771
false
1772
1772
} else { true }
1773
1773
});
@@ -1784,7 +1784,7 @@ to the next iteration, write `loop`.
1784
1784
# use println = io::println;
1785
1785
for each(&[2, 4, 8, 5, 16]) |n| {
1786
1786
if *n % 2 != 0 {
1787
- println(~ "found odd number!");
1787
+ println("found odd number!");
1788
1788
break;
1789
1789
}
1790
1790
}
@@ -1967,12 +1967,12 @@ impl int: Printable {
1967
1967
fn print() { io::println(fmt!("%d", self)) }
1968
1968
}
1969
1969
1970
- impl ~ str: Printable {
1970
+ impl & str: Printable {
1971
1971
fn print() { io::println(self) }
1972
1972
}
1973
1973
1974
1974
# 1.print();
1975
- # (~ "foo").print();
1975
+ # ("foo").print();
1976
1976
~~~~
1977
1977
1978
1978
Methods defined in an implementation of a trait may be called just like
@@ -2162,8 +2162,8 @@ additional modules.
2162
2162
2163
2163
~~~~
2164
2164
mod farm {
2165
- pub fn chicken() -> ~ str { ~ "cluck cluck" }
2166
- pub fn cow() -> ~ str { ~ "mooo" }
2165
+ pub fn chicken() -> & str { "cluck cluck" }
2166
+ pub fn cow() -> & str { "mooo" }
2167
2167
}
2168
2168
2169
2169
fn main() {
@@ -2360,13 +2360,13 @@ these two files:
2360
2360
~~~~
2361
2361
// world.rs
2362
2362
#[link(name = "world", vers = "1.0")];
2363
- pub fn explore() -> ~ str { ~ "world" }
2363
+ pub fn explore() -> & str { "world" }
2364
2364
~~~~
2365
2365
2366
2366
~~~~ {.xfail-test}
2367
2367
// main.rs
2368
2368
extern mod world;
2369
- fn main() { io::println(~ "hello " + world::explore()); }
2369
+ fn main() { io::println("hello " + world::explore()); }
2370
2370
~~~~
2371
2371
2372
2372
Now compile and run like this (adjust to your platform if necessary):
0 commit comments