]>
Commit | Line | Data |
---|---|---|
8bb4bdeb XL |
1 | # `box_patterns` |
2 | ||
3 | The tracking issue for this feature is: [#29641] | |
4 | ||
5 | [#29641]: https://github.com/rust-lang/rust/issues/29641 | |
6 | ||
7cac9316 | 7 | See also [`box_syntax`](language-features/box-syntax.html) |
8bb4bdeb XL |
8 | |
9 | ------------------------ | |
10 | ||
11 | Box patterns let you match on `Box<T>`s: | |
12 | ||
13 | ||
14 | ```rust | |
15 | #![feature(box_patterns)] | |
16 | ||
17 | fn main() { | |
18 | let b = Some(Box::new(5)); | |
19 | match b { | |
20 | Some(box n) if n < 0 => { | |
21 | println!("Box contains negative number {}", n); | |
22 | }, | |
23 | Some(box n) if n >= 0 => { | |
24 | println!("Box contains non-negative number {}", n); | |
25 | }, | |
26 | None => { | |
27 | println!("No box"); | |
28 | }, | |
29 | _ => unreachable!() | |
30 | } | |
31 | } | |
32 | ``` |