Skip to content

Commit 53d6b38

Browse files
committed
Rollup merge of #24753 - tynopex:patch-1, r=steveklabnik
Add section for range expressions.
2 parents f91216b + 4db0efb commit 53d6b38

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/doc/reference.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,6 +2806,33 @@ _panicked state_.
28062806
(["a", "b"])[10]; // panics
28072807
```
28082808

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

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

0 commit comments

Comments
 (0)