Skip to content

Commit

Permalink
Use match expression directly in guide.md
Browse files Browse the repository at this point in the history
Use a match expression directly in the println statement, instead of creating a second variable.
  • Loading branch information
jrincayc committed Oct 17, 2014
1 parent 93e589c commit ce83a24
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/doc/guide.md
Expand Up @@ -1255,8 +1255,9 @@ version, if we had forgotten the `Greater` case, for example, our program would
have happily compiled. If we forget in the `match`, it will not. Rust helps us
make sure to cover all of our bases.

`match` is also an expression, which means we can use it on the right hand side
of a `let` binding. We could also implement the previous line like this:
`match` is also an expression, which means we can use it on the right
hand side of a `let` binding or directly where an expression is
used. We could also implement the previous line like this:

```{rust}
fn cmp(a: int, b: int) -> Ordering {
Expand All @@ -1269,18 +1270,15 @@ fn main() {
let x = 5i;
let y = 10i;
let result = match cmp(x, y) {
println!("{}", match cmp(x, y) {
Less => "less",
Greater => "greater",
Equal => "equal",
};
println!("{}", result);
});
}
```

In this case, it doesn't make a lot of sense, as we are just making a temporary
string where we don't need to, but sometimes, it's a nice pattern.
Sometimes, it's a nice pattern.

# Looping

Expand Down

5 comments on commit ce83a24

@bors
Copy link
Contributor

@bors bors commented on ce83a24 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at jrincayc@ce83a24

@bors
Copy link
Contributor

@bors bors commented on ce83a24 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jrincayc/rust/match_exp = ce83a24 into auto

@bors
Copy link
Contributor

@bors bors commented on ce83a24 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jrincayc/rust/match_exp = ce83a24 merged ok, testing candidate = c46812f

@bors
Copy link
Contributor

@bors bors commented on ce83a24 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ce83a24 Oct 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c46812f

Please sign in to comment.