Skip to content

Commit ee2988f

Browse files
committed
---
yaml --- r: 14809 b: refs/heads/try c: 6f5853f h: refs/heads/master i: 14807: fa428ea v: v3
1 parent 07e615d commit ee2988f

Some content is hidden

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

106 files changed

+799
-2431
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: ac57bb38560fa35d883505af2e8e68498b436fe7
5+
refs/heads/try: 6f5853f5a1767e0c418fd5f348a795b76d701b3e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/doc/tutorial.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,23 @@ Rust program files are, by convention, given the extension `.rs`. Say
132132
we have a file `hello.rs` containing this program:
133133

134134
~~~~
135-
use std;
136135
fn main(args: [str]) {
137-
std::io::println("hello world from '" + args[0] + "'!");
136+
io::println("hello world from '" + args[0] + "'!");
138137
}
139138
~~~~
140139

141140
If the Rust compiler was installed successfully, running `rustc
142141
hello.rs` will produce a binary called `hello` (or `hello.exe`).
143142

144-
If you modify the program to make it invalid (for example, remove the
145-
`use std` line), and then compile it, you'll see an error message like
146-
this:
143+
If you modify the program to make it invalid (for example, change the
144+
function to an unknown name), and then compile it, you'll see an error
145+
message like this:
147146

148147
~~~~
149148
## notrust
150-
hello.rs:2:4: 2:20 error: unresolved modulename: std
151-
hello.rs:2 std::io::println("hello world!");
152-
^~~~~~~~~~~~~~~~
149+
hello.rs:2:4: 2:16 error: unresolved name: io::print_it
150+
hello.rs:2 io::print_it("hello world from '" + args[0] + "'!");
151+
^~~~~~~~~~~~
153152
~~~~
154153

155154
The Rust compiler tries to provide useful information when it runs
@@ -278,8 +277,8 @@ NOTE: The parser doesn't currently recognize non-ascii alphabetic
278277
characters. This is a bug that will eventually be fixed.
279278

280279
The double-colon (`::`) is used as a module separator, so
281-
`std::io::println` means 'the thing named `println` in the module
282-
named `io` in the module named `std`'.
280+
`io::println` means 'the thing named `println` in the module
281+
named `io`.
283282

284283
Rust will normally emit warnings about unused variables. These can be
285284
suppressed by using a variable name that starts with an underscore.
@@ -300,7 +299,7 @@ const repeat: uint = 5u;
300299
fn main() {
301300
let count = 0u;
302301
while count < repeat {
303-
std::io::println("Hi!");
302+
io::println("Hi!");
304303
count += 1u;
305304
}
306305
}
@@ -535,7 +534,7 @@ one is `#fmt`, a printf-style text formatting macro that is expanded
535534
at compile time.
536535

537536
~~~~
538-
std::io::println(#fmt("%s is %d", "the answer", 42));
537+
io::println(#fmt("%s is %d", "the answer", 42));
539538
~~~~
540539

541540
`#fmt` supports most of the directives that [printf][pf] supports, but
@@ -549,7 +548,7 @@ All syntax extensions look like `#word`. Another built-in one is
549548
compile-time.
550549

551550
~~~~
552-
std::io::println(#env("PATH"));
551+
io::println(#env("PATH"));
553552
~~~~
554553
# Control structures
555554

@@ -561,11 +560,11 @@ compulsory, an optional `else` clause can be appended, and multiple
561560

562561
~~~~
563562
if false {
564-
std::io::println("that's odd");
563+
io::println("that's odd");
565564
} else if true {
566-
std::io::println("right");
565+
io::println("right");
567566
} else {
568-
std::io::println("neither true nor false");
567+
io::println("neither true nor false");
569568
}
570569
~~~~
571570

@@ -598,10 +597,10 @@ the value.
598597
~~~~
599598
# let my_number = 1;
600599
alt my_number {
601-
0 { std::io::println("zero"); }
602-
1 | 2 { std::io::println("one or two"); }
603-
3 to 10 { std::io::println("three to ten"); }
604-
_ { std::io::println("something else"); }
600+
0 { io::println("zero"); }
601+
1 | 2 { io::println("one or two"); }
602+
3 to 10 { io::println("three to ten"); }
603+
_ { io::println("something else"); }
605604
}
606605
~~~~
607606

@@ -675,7 +674,7 @@ let x = 5;
675674
while true {
676675
x += x - 3;
677676
if x % 5 == 0 { break; }
678-
std::io::println(int::str(x));
677+
io::println(int::str(x));
679678
}
680679
~~~~
681680

@@ -697,7 +696,7 @@ When iterating over a vector, use `for` instead.
697696

698697
~~~~
699698
for elt in ["red", "green", "blue"] {
700-
std::io::println(elt);
699+
io::println(elt);
701700
}
702701
~~~~
703702

@@ -864,7 +863,7 @@ fn mk_appender(suffix: str) -> fn@(str) -> str {
864863
865864
fn main() {
866865
let shout = mk_appender("!");
867-
std::io::println(shout("hey ho, let's go"));
866+
io::println(shout("hey ho, let's go"));
868867
}
869868
~~~~
870869

@@ -1267,7 +1266,7 @@ with square brackets (zero-based):
12671266

12681267
~~~~
12691268
let myvec = [true, false, true, false];
1270-
if myvec[1] { std::io::println("boom"); }
1269+
if myvec[1] { io::println("boom"); }
12711270
~~~~
12721271

12731272
By default, vectors are immutable—you can not replace their elements.
@@ -1669,7 +1668,7 @@ mod farm {
16691668
fn cow() -> str { "mooo" }
16701669
}
16711670
fn main() {
1672-
std::io::println(farm::chicken());
1671+
io::println(farm::chicken());
16731672
}
16741673
~~~~
16751674

@@ -1788,7 +1787,7 @@ fn world() -> str { "world" }
17881787
// main.rs
17891788
use std;
17901789
use mylib;
1791-
fn main() { std::io::println("hello " + mylib::world()); }
1790+
fn main() { io::println("hello " + mylib::world()); }
17921791
~~~~
17931792

17941793
Now compile and run like this (adjust to your platform if necessary):
@@ -1810,21 +1809,21 @@ identifiers at the top of a file, module, or block.
18101809

18111810
~~~~
18121811
use std;
1813-
import std::io::println;
1812+
import io::println;
18141813
fn main() {
18151814
println("that was easy");
18161815
}
18171816
~~~~
18181817

18191818
It is also possible to import just the name of a module (`import
1820-
std::io;`, then use `io::println`), to import all identifiers exported
1821-
by a given module (`import std::io::*`), or to import a specific set
1819+
std::list;`, then use `list::find`), to import all identifiers exported
1820+
by a given module (`import io::*`), or to import a specific set
18221821
of identifiers (`import math::{min, max, pi}`).
18231822

18241823
You can rename an identifier when importing using the `=` operator:
18251824

18261825
~~~~
1827-
import prnt = std::io::println;
1826+
import prnt = io::println;
18281827
~~~~
18291828

18301829
## Exporting
@@ -2158,7 +2157,7 @@ fn sha1(data: str) -> str unsafe {
21582157
}
21592158
21602159
fn main(args: [str]) {
2161-
std::io::println(sha1(args[1]));
2160+
io::println(sha1(args[1]));
21622161
}
21632162
~~~~
21642163

@@ -2376,8 +2375,8 @@ module `task`. Let's begin with the simplest one, `task::spawn()`:
23762375
~~~~
23772376
let some_value = 22;
23782377
task::spawn {||
2379-
std::io::println("This executes in the child task.");
2380-
std::io::println(#fmt("%d", some_value));
2378+
io::println("This executes in the child task.");
2379+
io::println(#fmt("%d", some_value));
23812380
}
23822381
~~~~
23832382

0 commit comments

Comments
 (0)