Skip to content

Commit d028079

Browse files
darnuriaalexcrichton
authored andcommitted
Documentation : Tutorial improvement...
Refactoring examples on implementation of generics for linked list. Fixing typo of 'Note's for coherancy. Adding internal links inside the tutorial example with traits, generics etc...
1 parent 231832d commit d028079

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/doc/tutorial.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ fn main() {
133133
println!("hello?");
134134
}
135135
~~~~
136+
> ***Note:*** *Macros* are explained in the [Syntax extensions
137+
> (3.4)](#syntax-extensions) section.
136138
137139
If the Rust compiler was installed successfully, running `rustc
138140
hello.rs` will produce an executable called `hello` (or `hello.exe` on
@@ -1059,7 +1061,7 @@ box, while the owner holds onto a pointer to it:
10591061
list -> | Cons | 1 | ~ | -> | Cons | 2 | ~ | -> | Cons | 3 | ~ | -> | Nil |
10601062
+--------------+ +--------------+ +--------------+ +--------------+
10611063

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

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

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

1210-
Note that Rust doesn't guarantee [tail-call](http://en.wikipedia.org/wiki/Tail_call) optimization,
1211-
but LLVM is able to handle a simple case like this with optimizations enabled.
1212+
> ***Note:*** Rust doesn't guarantee [tail-call](http://en.wikipedia.org/wiki/Tail_call) optimization,
1213+
> but LLVM is able to handle a simple case like this with optimizations enabled.
12121214
12131215
## Lists of other types
12141216

@@ -1218,6 +1220,9 @@ element type.
12181220

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

1223+
> ***Note:*** The following code introduces generics, which are explained in a
1224+
> [dedicated section](#generics).
1225+
12211226
~~~
12221227
enum List<T> {
12231228
Cons(T, ~List<T>),
@@ -1336,9 +1341,13 @@ impl<T: Eq> Eq for List<T> {
13361341
13371342
let xs = Cons(5, ~Cons(10, ~Nil));
13381343
let ys = Cons(5, ~Cons(10, ~Nil));
1344+
// The methods below are part of the Eq trait,
1345+
// which we implemented on our linked list.
13391346
assert!(xs.eq(&ys));
1340-
assert!(xs == ys);
13411347
assert!(!xs.ne(&ys));
1348+
1349+
// The Eq trait also allows us to use the shorthand infix operators.
1350+
assert!(xs == ys);
13421351
assert!(!(xs != ys));
13431352
~~~
13441353

0 commit comments

Comments
 (0)