]> git.lizzy.rs Git - rust.git/commitdiff
Update reference.md
authortynopex <tynopex@users.noreply.github.com>
Fri, 24 Apr 2015 00:38:11 +0000 (20:38 -0400)
committertynopex <tynopex@users.noreply.github.com>
Fri, 24 Apr 2015 00:38:11 +0000 (20:38 -0400)
Add section for range expressions.

src/doc/reference.md

index d918a320e63a909c3298c213cb2188ddab0492b0..b3a07bb6452adebace8f29a3cf235a5024648918 100644 (file)
@@ -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,