Skip to content

Commit

Permalink
Add pattern guard docs to language ref
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Oct 31, 2011
1 parent 9303572 commit 151aaf8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions doc/rust.texi
Expand Up @@ -676,6 +676,7 @@ The keywords are:
@tab @code{fail}
@tab @code{ret}
@tab @code{be}
@item @code{when}
@end multitable

@node Ref.Lex.Res
Expand Down Expand Up @@ -3361,6 +3362,18 @@ let message = alt x @{
@}
@end example

Finally, alt patterns can accept @emph{pattern guards} to further refine the
criteria for matching a case. Pattern guards appear after the pattern and
consist of a bool-typed expression following the @emph{when} keyword. A pattern
guard may refer to the variables bound within the pattern they follow.

@example
let message = alt maybe_digit @{
some(x) when x < 10 @{ process_digit(x) @}
some(x) @{ process_other(x) @}
@}
@end example


@node Ref.Expr.Alt.Type
@subsubsection Ref.Expr.Alt.Type
Expand Down

0 comments on commit 151aaf8

Please sign in to comment.