From 4db0efb45c5b7686f88773b33aa42959f71109c9 Mon Sep 17 00:00:00 2001 From: tynopex Date: Thu, 23 Apr 2015 20:38:11 -0400 Subject: [PATCH] Update reference.md Add section for range expressions. --- src/doc/reference.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/doc/reference.md b/src/doc/reference.md index d918a320e63..b3a07bb6452 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2812,6 +2812,33 @@ _panicked state_. (["a", "b"])[10]; // panics ``` +### Range expressions + +```{.ebnf .gram} +range_expr : expr ".." expr | + expr ".." | + ".." expr | + ".." ; +``` + +The `..` operator will construct an object of one of the `std::ops::Range` variants. + +``` +1..2; // std::ops::Range +3..; // std::ops::RangeFrom +..4; // std::ops::RangeTo +..; // std::ops::RangeFull +``` + +The following expressions are equivalent. + +``` +let x = std::ops::Range {start: 0, end: 10}; +let y = 0..10; + +assert_eq!(x,y); +``` + ### Unary operator expressions Rust defines three unary operators. They are all written as prefix operators,