Skip to content

Commit 4db0efb

Browse files
committed
Update reference.md
Add section for range expressions.
1 parent 90bed3f commit 4db0efb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/doc/reference.md

+27
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,33 @@ _panicked state_.
28122812
(["a", "b"])[10]; // panics
28132813
```
28142814

2815+
### Range expressions
2816+
2817+
```{.ebnf .gram}
2818+
range_expr : expr ".." expr |
2819+
expr ".." |
2820+
".." expr |
2821+
".." ;
2822+
```
2823+
2824+
The `..` operator will construct an object of one of the `std::ops::Range` variants.
2825+
2826+
```
2827+
1..2; // std::ops::Range
2828+
3..; // std::ops::RangeFrom
2829+
..4; // std::ops::RangeTo
2830+
..; // std::ops::RangeFull
2831+
```
2832+
2833+
The following expressions are equivalent.
2834+
2835+
```
2836+
let x = std::ops::Range {start: 0, end: 10};
2837+
let y = 0..10;
2838+
2839+
assert_eq!(x,y);
2840+
```
2841+
28152842
### Unary operator expressions
28162843

28172844
Rust defines three unary operators. They are all written as prefix operators,

0 commit comments

Comments
 (0)