Skip to content

Commit 92743dc

Browse files
committed
Move the world over to using the new style string literals and types. Closes #2907.
1 parent 5c5065e commit 92743dc

File tree

424 files changed

+8147
-8079
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

424 files changed

+8147
-8079
lines changed

doc/rust.md

+40-40
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ Two examples of paths with type arguments:
449449
# import std::map;
450450
# fn f() {
451451
# fn id<T:copy>(t: T) -> T { t }
452-
type t = map::hashmap<int,str>; // Type arguments used in a type expression
452+
type t = map::hashmap<int,~str>; // Type arguments used in a type expression
453453
let x = id::<int>(10); // Type arguments used in a call expression
454454
# }
455455
~~~~
@@ -563,7 +563,7 @@ a referencing crate file, or by the filename of the source file itself.
563563

564564
A source file that contains a `main` function can be compiled to an
565565
executable. If a `main` function is present, it must have no [type parameters](#type-parameters)
566-
and no [constraints](#constraints). Its return type must be [`nil`](#primitive-types) and it must either have no arguments, or a single argument of type `[str]`.
566+
and no [constraints](#constraints). Its return type must be [`nil`](#primitive-types) and it must either have no arguments, or a single argument of type `[~str]`.
567567

568568
# Items and attributes
569569

@@ -745,8 +745,8 @@ fn main() {
745745
log(info, some(1.0));
746746
747747
// Equivalent to 'log(core::info,
748-
// core::str::hash(core::str::slice("foo", 0u, 1u)));'
749-
log(info, hash(slice("foo", 0u, 1u)));
748+
// core::str::hash(core::str::slice(~"foo", 0u, 1u)));'
749+
log(info, hash(slice(~"foo", 0u, 1u)));
750750
}
751751
~~~~
752752

@@ -861,7 +861,7 @@ A special kind of function can be declared with a `!` character where the
861861
output slot type would normally be. For example:
862862

863863
~~~~
864-
fn my_err(s: str) -> ! {
864+
fn my_err(s: ~str) -> ! {
865865
log(info, s);
866866
fail;
867867
}
@@ -881,14 +881,14 @@ were declared without the `!` annotation, the following code would not
881881
typecheck:
882882

883883
~~~~
884-
# fn my_err(s: str) -> ! { fail }
884+
# fn my_err(s: ~str) -> ! { fail }
885885
886886
fn f(i: int) -> int {
887887
if i == 42 {
888888
ret 42;
889889
}
890890
else {
891-
my_err("Bad number!");
891+
my_err(~"Bad number!");
892892
}
893893
}
894894
~~~~
@@ -1497,7 +1497,7 @@ string, boolean value, or the nil value.
14971497

14981498
~~~~~~~~ {.literals}
14991499
(); // nil type
1500-
"hello"; // string type
1500+
~"hello"; // string type
15011501
'5'; // character type
15021502
5; // integer type
15031503
~~~~~~~~
@@ -1510,7 +1510,7 @@ values.
15101510

15111511
~~~~~~~~ {.tuple}
15121512
(0f, 4.5f);
1513-
("a", 4u, true);
1513+
(~"a", 4u, true);
15141514
~~~~~~~~
15151515

15161516
### Record expressions
@@ -1529,8 +1529,8 @@ written before its name.
15291529

15301530
~~~~
15311531
{x: 10f, y: 20f};
1532-
{name: "Joe", age: 35u, score: 100_000};
1533-
{ident: "X", mut count: 0u};
1532+
{name: ~"Joe", age: 35u, score: 100_000};
1533+
{ident: ~"X", mut count: 0u};
15341534
~~~~
15351535

15361536
The order of the fields in a record expression is significant, and
@@ -1594,7 +1594,7 @@ When no mutability is specified, the vector is immutable.
15941594

15951595
~~~~
15961596
~[1, 2, 3, 4];
1597-
~["a", "b", "c", "d"];
1597+
~[~"a", ~"b", ~"c", ~"d"];
15981598
~[mut 0u8, 0u8, 0u8, 0u8];
15991599
~~~~
16001600

@@ -1620,7 +1620,7 @@ task in a _failing state_.
16201620
16211621
(~[1, 2, 3, 4])[0];
16221622
(~[mut 'x', 'y'])[1] = 'z';
1623-
(~["a", "b"])[10]; // fails
1623+
(~[~"a", ~"b"])[10]; // fails
16241624
16251625
# }
16261626
~~~~
@@ -1965,7 +1965,7 @@ An example:
19651965
# let println = io::println;
19661966
19671967
while i < 10 {
1968-
println("hello\n");
1968+
println(~"hello\n");
19691969
i = i + 1;
19701970
}
19711971
~~~~
@@ -2103,9 +2103,9 @@ enum list<X> { nil, cons(X, @list<X>) }
21032103
let x: list<int> = cons(10, @cons(11, @nil));
21042104
21052105
alt x {
2106-
cons(_, @nil) { fail "singleton list"; }
2106+
cons(_, @nil) { fail ~"singleton list"; }
21072107
cons(*) { ret; }
2108-
nil { fail "empty list"; }
2108+
nil { fail ~"empty list"; }
21092109
}
21102110
~~~~
21112111

@@ -2152,28 +2152,28 @@ When matching fields of a record, the fields being matched are specified
21522152
first, then a placeholder (`_`) represents the remaining fields.
21532153

21542154
~~~~
2155-
# type options = {choose: bool, size: str};
2156-
# type player = {player: str, stats: (), options: options};
2155+
# type options = {choose: bool, size: ~str};
2156+
# type player = {player: ~str, stats: (), options: options};
21572157
# fn load_stats() { }
21582158
# fn choose_player(r: player) { }
21592159
# fn next_player() { }
21602160
21612161
fn main() {
21622162
let r = {
2163-
player: "ralph",
2163+
player: ~"ralph",
21642164
stats: load_stats(),
21652165
options: {
21662166
choose: true,
2167-
size: "small"
2167+
size: ~"small"
21682168
}
21692169
};
21702170
21712171
alt r {
21722172
{options: {choose: true, _}, _} {
21732173
choose_player(r)
21742174
}
2175-
{player: p, options: {size: "small", _}, _} {
2176-
log(info, p + " is small");
2175+
{player: p, options: {size: ~"small", _}, _} {
2176+
log(info, p + ~" is small");
21772177
}
21782178
_ {
21792179
next_player();
@@ -2189,9 +2189,9 @@ range of values may be specified with `to`. For example:
21892189
# let x = 2;
21902190
21912191
let message = alt x {
2192-
0 | 1 { "not many" }
2193-
2 to 9 { "a few" }
2194-
_ { "lots" }
2192+
0 | 1 { ~"not many" }
2193+
2 to 9 { ~"a few" }
2194+
_ { ~"lots" }
21952195
};
21962196
~~~~
21972197

@@ -2250,9 +2250,9 @@ the `note` to the internal logging diagnostic buffer.
22502250
An example of a `note` expression:
22512251

22522252
~~~~{.xfail-test}
2253-
fn read_file_lines(path: str) -> ~[str] {
2253+
fn read_file_lines(path: ~str) -> ~[~str] {
22542254
note path;
2255-
let r: [str];
2255+
let r: [~str];
22562256
let f: file = open_read(path);
22572257
lines(f) |s| {
22582258
r += ~[s];
@@ -2323,13 +2323,13 @@ The following examples all produce the same output, logged at the `error`
23232323
logging level:
23242324

23252325
~~~~
2326-
# let filename = "bulbasaur";
2326+
# let filename = ~"bulbasaur";
23272327
23282328
// Full version, logging a value.
2329-
log(core::error, "file not found: " + filename);
2329+
log(core::error, ~"file not found: " + filename);
23302330
23312331
// Log-level abbreviated, since core::* is imported by default.
2332-
log(error, "file not found: " + filename);
2332+
log(error, ~"file not found: " + filename);
23332333
23342334
// Formatting the message using a format-string and #fmt
23352335
log(error, #fmt("file not found: %s", filename));
@@ -2627,12 +2627,12 @@ type `float` may not be equal to the largest *supported* floating-point type.
26272627

26282628
### Textual types
26292629

2630-
The types `char` and `str` hold textual data.
2630+
The types `char` and `~str` hold textual data.
26312631

26322632
A value of type `char` is a Unicode character, represented as a 32-bit
26332633
unsigned word holding a UCS-4 codepoint.
26342634

2635-
A value of type `str` is a Unicode string, represented as a vector of 8-bit
2635+
A value of type `~str` is a Unicode string, represented as a vector of 8-bit
26362636
unsigned bytes holding a sequence of UTF-8 codepoints.
26372637

26382638

@@ -2670,10 +2670,10 @@ order specified by the tuple type.
26702670
An example of a tuple type and its use:
26712671

26722672
~~~~
2673-
type pair = (int,str);
2674-
let p: pair = (10,"hello");
2673+
type pair = (int,~str);
2674+
let p: pair = (10,~"hello");
26752675
let (a, b) = p;
2676-
assert b != "world";
2676+
assert b != ~"world";
26772677
~~~~
26782678

26792679
### Vector types
@@ -2837,7 +2837,7 @@ For example, this code:
28372837
~~~~~~~~
28382838
# let mut s;
28392839
2840-
s = "hello, world";
2840+
s = ~"hello, world";
28412841
io::println(s);
28422842
~~~~~~~~
28432843

@@ -2862,8 +2862,8 @@ Whereas this code:
28622862

28632863

28642864
~~~~~~~~
2865-
# fn x() -> str { "" }
2866-
# fn y() -> str { "" }
2865+
# fn x() -> ~str { ~"" }
2866+
# fn y() -> ~str { ~"" }
28672867
28682868
io::println(x() + y());
28692869
~~~~~~~~
@@ -3364,7 +3364,7 @@ An example of a send:
33643364
~~~~
33653365
let po = comm::port();
33663366
let ch = comm::chan(po);
3367-
comm::send(ch, "hello, world");
3367+
comm::send(ch, ~"hello, world");
33683368
~~~~
33693369

33703370

@@ -3380,7 +3380,7 @@ An example of a *receive*:
33803380
~~~~~~~~
33813381
# let po = comm::port();
33823382
# let ch = comm::chan(po);
3383-
# comm::send(ch, "");
3383+
# comm::send(ch, ~"");
33843384
let s = comm::recv(po);
33853385
~~~~~~~~
33863386

0 commit comments

Comments
 (0)