]>
Commit | Line | Data |
---|---|---|
3157f602 XL |
1 | // Copyright 2016 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 | ||
3157f602 XL |
11 | fn tuple() { |
12 | let x = (1, 2, 3); | |
13 | match x { | |
14 | (a, b, ..) => { | |
15 | assert_eq!(a, 1); | |
16 | assert_eq!(b, 2); | |
17 | } | |
18 | } | |
19 | match x { | |
20 | (.., b, c) => { | |
21 | assert_eq!(b, 2); | |
22 | assert_eq!(c, 3); | |
23 | } | |
24 | } | |
25 | match x { | |
26 | (a, .., c) => { | |
27 | assert_eq!(a, 1); | |
28 | assert_eq!(c, 3); | |
29 | } | |
30 | } | |
31 | match x { | |
32 | (a, b, c) => { | |
33 | assert_eq!(a, 1); | |
34 | assert_eq!(b, 2); | |
35 | assert_eq!(c, 3); | |
36 | } | |
37 | } | |
38 | match x { | |
39 | (a, b, c, ..) => { | |
40 | assert_eq!(a, 1); | |
41 | assert_eq!(b, 2); | |
42 | assert_eq!(c, 3); | |
43 | } | |
44 | } | |
45 | match x { | |
46 | (.., a, b, c) => { | |
47 | assert_eq!(a, 1); | |
48 | assert_eq!(b, 2); | |
49 | assert_eq!(c, 3); | |
50 | } | |
51 | } | |
52 | } | |
53 | ||
54 | fn tuple_struct() { | |
55 | struct S(u8, u8, u8); | |
56 | ||
57 | let x = S(1, 2, 3); | |
58 | match x { | |
59 | S(a, b, ..) => { | |
60 | assert_eq!(a, 1); | |
61 | assert_eq!(b, 2); | |
62 | } | |
63 | } | |
64 | match x { | |
65 | S(.., b, c) => { | |
66 | assert_eq!(b, 2); | |
67 | assert_eq!(c, 3); | |
68 | } | |
69 | } | |
70 | match x { | |
71 | S(a, .., c) => { | |
72 | assert_eq!(a, 1); | |
73 | assert_eq!(c, 3); | |
74 | } | |
75 | } | |
76 | match x { | |
77 | S(a, b, c) => { | |
78 | assert_eq!(a, 1); | |
79 | assert_eq!(b, 2); | |
80 | assert_eq!(c, 3); | |
81 | } | |
82 | } | |
83 | match x { | |
84 | S(a, b, c, ..) => { | |
85 | assert_eq!(a, 1); | |
86 | assert_eq!(b, 2); | |
87 | assert_eq!(c, 3); | |
88 | } | |
89 | } | |
90 | match x { | |
91 | S(.., a, b, c) => { | |
92 | assert_eq!(a, 1); | |
93 | assert_eq!(b, 2); | |
94 | assert_eq!(c, 3); | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | fn main() { | |
100 | tuple(); | |
101 | tuple_struct(); | |
102 | } |