Skip to content

Commit

Permalink
Update reference.md
Browse files Browse the repository at this point in the history
Add section for range expressions.
  • Loading branch information
tynopex committed Apr 24, 2015
1 parent 90bed3f commit 4db0efb
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/doc/reference.md
Expand Up @@ -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,
Expand Down

0 comments on commit 4db0efb

Please sign in to comment.