Skip to content

Commit 6b98704

Browse files
Add newer range patterns to unstable book
1 parent 36bcf40 commit 6b98704

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `exclusive_range_pattern`
2+
3+
The tracking issue for this feature is: [#37854].
4+
5+
6+
[#67264]: https://github.com/rust-lang/rust/issues/67264
7+
[#37854]: https://github.com/rust-lang/rust/issues/37854
8+
-----
9+
10+
The `exclusive_range_pattern` feature allows non-inclusive range
11+
patterns (`0..10`) to be used in appropriate pattern matching
12+
contexts. It also can be combined with `#![feature(half_open_range_patterns]`
13+
to be able to use RangeTo patterns (`..10`).
14+
15+
It also enabled RangeFrom patterns but that has since been
16+
stabilized.
17+
18+
```rust
19+
#![feature(exclusive_range_pattern)]
20+
match x {
21+
0..10 => println!("single digit"),
22+
10 => println!("ten isn't part of the above range"),
23+
_ => println!("nor is everything else.")
24+
}
25+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `half_open_range_patterns`
2+
3+
The tracking issue for this feature is: [#67264]
4+
It is part of the `#![exclusive_range_pattern]` feature,
5+
tracked at [#37854].
6+
7+
[#67264]: https://github.com/rust-lang/rust/issues/67264
8+
[#37854]: https://github.com/rust-lang/rust/issues/37854
9+
-----
10+
11+
The `half_open_range_patterns` feature allows RangeTo patterns
12+
(`..10`) to be used in appropriate pattern matching contexts.
13+
This requires also enabling the `exclusive_range_pattern` feature.
14+
15+
It also enabled RangeFrom patterns but that has since been
16+
stabilized.
17+
18+
```rust
19+
#![feature(half_open_range_patterns)]
20+
#![feature(exclusive_range_pattern)]
21+
match x {
22+
..10 => println!("got it"),
23+
0 => println!("zilch")
24+
}
25+
```

0 commit comments

Comments
 (0)