Rollup merge of #24753 - tynopex:patch-1, r=steveklabnik
Add section for range expressions.
This commit is contained in:
commit
53d6b38c21
@ -2806,6 +2806,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,
|
||||
|
Loading…
Reference in New Issue
Block a user