]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/vec-tail-matching.rs
Fix BTreeMap example typo
[rust.git] / src / test / run-pass / vec-tail-matching.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12
13 #![feature(slice_patterns)]
14
15 struct Foo {
16     string: String
17 }
18
19 pub fn main() {
20     let x = [
21         Foo { string: "foo".to_string() },
22         Foo { string: "bar".to_string() },
23         Foo { string: "baz".to_string() }
24     ];
25     match x {
26         [ref first, tail..] => {
27             assert_eq!(first.string, "foo".to_string());
28             assert_eq!(tail.len(), 2);
29             assert_eq!(tail[0].string, "bar".to_string());
30             assert_eq!(tail[1].string, "baz".to_string());
31
32             match tail {
33                 [Foo { .. }, _, Foo { .. }, _tail..] => {
34                     unreachable!();
35                 }
36                 [Foo { string: ref a }, Foo { string: ref b }] => {
37                     assert_eq!("bar", &a[0..a.len()]);
38                     assert_eq!("baz", &b[0..b.len()]);
39                 }
40                 _ => {
41                     unreachable!();
42                 }
43             }
44         }
45     }
46 }