@@ -128,7 +128,7 @@ we have a file `hello.rs` containing this program:
128
128
129
129
~~~~
130
130
fn main() {
131
- io::println("hello?");
131
+ core:: io::println("hello?");
132
132
}
133
133
~~~~
134
134
@@ -142,8 +142,8 @@ error. If you introduce an error into the program (for example, by changing
142
142
an error message like this:
143
143
144
144
~~~~ {.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?");
147
147
^~~~~~~~~~~~~~~~~~~~~~~
148
148
~~~~
149
149
@@ -180,20 +180,21 @@ JavaScript, C#, or PHP), Rust will feel familiar. Code is arranged
180
180
in blocks delineated by curly braces; there are control structures
181
181
for branching and looping, like the familiar ` if ` and ` while ` ; function
182
182
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++.
184
185
185
186
The main surface difference to be aware of is that the condition at
186
187
the head of control structures like ` if ` and ` while ` do not require
187
188
parentheses, while their bodies * must* be wrapped in
188
189
braces. Single-statement, unbraced bodies are not allowed.
189
190
190
191
~~~~
191
- # fn recalibrate_universe () -> bool { true }
192
+ # mod universe { fn recalibrate () -> bool { true } }
192
193
fn main() {
193
194
/* A simple loop */
194
195
loop {
195
196
// A tricky calculation
196
- if recalibrate_universe () {
197
+ if universe::recalibrate () {
197
198
return;
198
199
}
199
200
}
@@ -209,16 +210,11 @@ let hi = "hi";
209
210
let mut count = 0;
210
211
211
212
while count < 10 {
212
- io::println(hi );
213
+ core:: io::println(fmt!("count: %?", i) );
213
214
count += 1;
214
215
}
215
216
~~~~
216
217
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
-
222
218
Although Rust can almost always infer the types of local variables, you
223
219
can specify a variable's type by following it with a colon, then the type
224
220
name. Constants, an the other hand, always require a type annotation.
0 commit comments