From 151aaf84ce5b4838f6d1be014681b3135a69b5db Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 31 Oct 2011 15:37:40 -0700 Subject: [PATCH] Add pattern guard docs to language ref --- doc/rust.texi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/rust.texi b/doc/rust.texi index 2a5a7c89249..724e5086eae 100644 --- a/doc/rust.texi +++ b/doc/rust.texi @@ -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 @@ -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