Skip to content

Commit 30fac74

Browse files
committed
tutorial: Try to fit the early discussion of :: in better
1 parent cbddd5e commit 30fac74

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

doc/tutorial.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ we have a file `hello.rs` containing this program:
128128

129129
~~~~
130130
fn main() {
131-
io::println("hello?");
131+
core::io::println("hello?");
132132
}
133133
~~~~
134134

@@ -142,8 +142,8 @@ error. If you introduce an error into the program (for example, by changing
142142
an error message like this:
143143

144144
~~~~ {.notrust}
145-
hello.rs:2:4: 2:16 error: unresolved name: io::print_with_unicorns
146-
hello.rs:2 io::print_with_unicorns("hello?");
145+
hello.rs:2:4: 2:16 error: unresolved name: core::io::print_with_unicorns
146+
hello.rs:2 core::io::print_with_unicorns("hello?");
147147
^~~~~~~~~~~~~~~~~~~~~~~
148148
~~~~
149149

@@ -180,20 +180,21 @@ JavaScript, C#, or PHP), Rust will feel familiar. Code is arranged
180180
in blocks delineated by curly braces; there are control structures
181181
for branching and looping, like the familiar `if` and `while`; function
182182
calls are written `myfunc(arg1, arg2)`; operators are written the same
183-
and mostly have the same precedence as in C; comments are again like C.
183+
and mostly have the same precedence as in C; comments are again like C;
184+
module names are separated with double-colon, `::`, as with C++.
184185

185186
The main surface difference to be aware of is that the condition at
186187
the head of control structures like `if` and `while` do not require
187188
parentheses, while their bodies *must* be wrapped in
188189
braces. Single-statement, unbraced bodies are not allowed.
189190

190191
~~~~
191-
# fn recalibrate_universe() -> bool { true }
192+
# mod universe { fn recalibrate() -> bool { true } }
192193
fn main() {
193194
/* A simple loop */
194195
loop {
195196
// A tricky calculation
196-
if recalibrate_universe() {
197+
if universe::recalibrate() {
197198
return;
198199
}
199200
}
@@ -209,16 +210,11 @@ let hi = "hi";
209210
let mut count = 0;
210211
211212
while count < 10 {
212-
io::println(hi);
213+
core::io::println(fmt!("count: %?", i));
213214
count += 1;
214215
}
215216
~~~~
216217

217-
The name of the function that prints a line of text, `io::println`, is
218-
qualified: it refers to the function named `println` that's defined in the
219-
module `io`. In Rust, a double colon separates parts of a
220-
qualified name. For more details, see the section on [crates](#crates).
221-
222218
Although Rust can almost always infer the types of local variables, you
223219
can specify a variable's type by following it with a colon, then the type
224220
name. Constants, an the other hand, always require a type annotation.

0 commit comments

Comments
 (0)