diff options
author | Brian Anderson <banderson@mozilla.com> | 2012-12-20 13:42:13 -0800 |
---|---|---|
committer | Brian Anderson <banderson@mozilla.com> | 2012-12-20 16:32:43 -0800 |
commit | 30fac74bf3c370173d9c2cf1e023a6128488f5db (patch) | |
tree | d3cd32dd1ec3533fcb29b5d3f4ccbab053ed6667 | |
parent | cbddd5ed3417dbdf6849a0ffb579cc2b0284d447 (diff) |
tutorial: Try to fit the early discussion of :: in better
-rw-r--r-- | doc/tutorial.md | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md index 38e6c0f107c..74943df8d00 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -128,7 +128,7 @@ we have a file `hello.rs` containing this program: ~~~~ fn main() { - io::println("hello?"); + core::io::println("hello?"); } ~~~~ @@ -142,8 +142,8 @@ error. If you introduce an error into the program (for example, by changing an error message like this: ~~~~ {.notrust} -hello.rs:2:4: 2:16 error: unresolved name: io::print_with_unicorns -hello.rs:2 io::print_with_unicorns("hello?"); +hello.rs:2:4: 2:16 error: unresolved name: core::io::print_with_unicorns +hello.rs:2 core::io::print_with_unicorns("hello?"); ^~~~~~~~~~~~~~~~~~~~~~~ ~~~~ @@ -180,7 +180,8 @@ JavaScript, C#, or PHP), Rust will feel familiar. Code is arranged in blocks delineated by curly braces; there are control structures for branching and looping, like the familiar `if` and `while`; function calls are written `myfunc(arg1, arg2)`; operators are written the same -and mostly have the same precedence as in C; comments are again like C. +and mostly have the same precedence as in C; comments are again like C; +module names are separated with double-colon, `::`, as with C++. The main surface difference to be aware of is that the condition at the head of control structures like `if` and `while` do not require @@ -188,12 +189,12 @@ parentheses, while their bodies *must* be wrapped in braces. Single-statement, unbraced bodies are not allowed. ~~~~ -# fn recalibrate_universe() -> bool { true } +# mod universe { fn recalibrate() -> bool { true } } fn main() { /* A simple loop */ loop { // A tricky calculation - if recalibrate_universe() { + if universe::recalibrate() { return; } } @@ -209,16 +210,11 @@ let hi = "hi"; let mut count = 0; while count < 10 { - io::println(hi); + core::io::println(fmt!("count: %?", i)); count += 1; } ~~~~ -The name of the function that prints a line of text, `io::println`, is -qualified: it refers to the function named `println` that's defined in the -module `io`. In Rust, a double colon separates parts of a -qualified name. For more details, see the section on [crates](#crates). - Although Rust can almost always infer the types of local variables, you can specify a variable's type by following it with a colon, then the type name. Constants, an the other hand, always require a type annotation. |