]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/language-features/box-patterns.md
Rollup merge of #61423 - davidtwco:correct-symbol-mangling, r=eddyb
[rust.git] / src / doc / unstable-book / src / language-features / box-patterns.md
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
7 See also [`box_syntax`](box-syntax.md)
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 ```