Skip to content

Commit d943b0f

Browse files
committed
auto merge of #13907 : iliekturtles/rust/tutorial, r=alexcrichton
Some minor clarifications and fixes.
2 parents fd625dd + 055cbde commit d943b0f

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/doc/tutorial.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,16 @@ Unlike in C, there is no "falling through" between arms: only one arm
468468
executes, and it doesn't have to explicitly `break` out of the
469469
construct when it is finished.
470470

471-
A `match` arm consists of a *pattern*, then an arrow `=>`, followed by
472-
an *action* (expression). Literals are valid patterns and match only
473-
their own value. A single arm may match multiple different patterns by
474-
combining them with the pipe operator (`|`), so long as every pattern
475-
binds the same set of variables. Ranges of numeric literal patterns
476-
can be expressed with two dots, as in `M..N`. The underscore (`_`) is
477-
a wildcard pattern that matches any single value. (`..`) is a different
478-
wildcard that can match one or more fields in an `enum` variant.
479-
480-
The patterns in a match arm are followed by a fat arrow, `=>`, then an
481-
expression to evaluate. Each case is separated by commas. It's often
482-
convenient to use a block expression for each case, in which case the
483-
commas are optional.
471+
A `match` arm consists of a *pattern*, then a fat arrow `=>`, followed
472+
by an *action* (expression). Each case is separated by commas. It is
473+
often convenient to use a block expression for each case, in which case
474+
the commas are optional as shown below. Literals are valid patterns and
475+
match only their own value. A single arm may match multiple different
476+
patterns by combining them with the pipe operator (`|`), so long as every
477+
pattern binds the same set of variables. Ranges of numeric literal
478+
patterns can be expressed with two dots, as in `M..N`. The underscore
479+
(`_`) is a wildcard pattern that matches any single value. (`..`) is a
480+
different wildcard that can match one or more fields in an `enum` variant.
484481

485482
~~~
486483
# let my_number = 1;
@@ -1416,7 +1413,7 @@ contains a point, but allocated in a different location:
14161413
14171414
~~~
14181415
# struct Point { x: f64, y: f64 }
1419-
let on_the_stack : Point = Point { x: 3.0, y: 4.0 };
1416+
let on_the_stack : Point = Point { x: 3.0, y: 4.0 };
14201417
let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 };
14211418
~~~
14221419
@@ -2587,11 +2584,18 @@ for `Eq` and can be used with the equality operators, and that a value
25872584
of type `ABC` can be randomly generated and converted to a string:
25882585

25892586
~~~
2587+
extern crate rand;
2588+
25902589
#[deriving(Eq)]
25912590
struct Circle { radius: f64 }
25922591
2593-
#[deriving(Clone, Show)]
2592+
#[deriving(Rand, Show)]
25942593
enum ABC { A, B, C }
2594+
2595+
fn main() {
2596+
// Use the Show trait to print "A, B, C."
2597+
println!("{}, {}, {}", A, B, C);
2598+
}
25952599
~~~
25962600

25972601
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,

0 commit comments

Comments
 (0)