Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation : Tutorial improvement. #12472

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ fn main() {
println!("hello?");
}
~~~~
> ***Note:*** *Macros* are explained in the [Syntax extensions
> (3.4)](#syntax-extensions) section.

If the Rust compiler was installed successfully, running `rustc
hello.rs` will produce an executable called `hello` (or `hello.exe` on
Expand Down Expand Up @@ -1059,7 +1061,7 @@ box, while the owner holds onto a pointer to it:
list -> | Cons | 1 | ~ | -> | Cons | 2 | ~ | -> | Cons | 3 | ~ | -> | Nil |
+--------------+ +--------------+ +--------------+ +--------------+

> Note: the above diagram shows the logical contents of the enum. The actual
> ***Note:*** the above diagram shows the logical contents of the enum. The actual
> memory layout of the enum may vary. For example, for the `List` enum shown
> above, Rust guarantees that there will be no enum tag field in the actual
> structure. See the language reference for more details.
Expand Down Expand Up @@ -1114,7 +1116,7 @@ let z = x; // no new memory allocated, `x` can no longer be used
~~~~

The `clone` method is provided by the `Clone` trait, and can be derived for
our `List` type. Traits will be explained in detail later.
our `List` type. Traits will be explained in detail [later](#traits).

~~~{.ignore}
#[deriving(Clone)]
Expand Down Expand Up @@ -1207,8 +1209,8 @@ let ys = Cons(5, ~Cons(10, ~Nil));
assert!(eq(&xs, &ys));
~~~

Note that Rust doesn't guarantee [tail-call](http://en.wikipedia.org/wiki/Tail_call) optimization,
but LLVM is able to handle a simple case like this with optimizations enabled.
> ***Note:*** Rust doesn't guarantee [tail-call](http://en.wikipedia.org/wiki/Tail_call) optimization,
> but LLVM is able to handle a simple case like this with optimizations enabled.

## Lists of other types

Expand All @@ -1218,6 +1220,9 @@ element type.

The `u32` in the previous definition can be substituted with a type parameter:

> ***Note:*** The following code introduces generics, which are explained in a
> [dedicated section](#generics).

~~~
enum List<T> {
Cons(T, ~List<T>),
Expand Down Expand Up @@ -1336,9 +1341,13 @@ impl<T: Eq> Eq for List<T> {

let xs = Cons(5, ~Cons(10, ~Nil));
let ys = Cons(5, ~Cons(10, ~Nil));
// The methods below are part of the Eq trait,
// which we implemented on our linked list.
assert!(xs.eq(&ys));
assert!(xs == ys);
assert!(!xs.ne(&ys));

// The Eq trait also allows us to use the shorthand infix operators.
assert!(xs == ys);
assert!(!(xs != ys));
~~~

Expand Down