]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
1 | // Copyright 2013 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 | ||
83c7162d | 11 | #![feature(repr_packed)] |
c34b1796 | 12 | |
1a4d82fc | 13 | #[repr(packed)] |
83c7162d XL |
14 | struct Foo1 { |
15 | bar: u8, | |
16 | baz: usize | |
17 | } | |
18 | ||
19 | #[repr(packed(2))] | |
20 | struct Foo2 { | |
21 | bar: u8, | |
22 | baz: usize | |
23 | } | |
24 | ||
25 | #[repr(C, packed(4))] | |
26 | struct Foo4C { | |
970d7e83 | 27 | bar: u8, |
c34b1796 | 28 | baz: usize |
970d7e83 | 29 | } |
223e47cc | 30 | |
1a4d82fc | 31 | pub fn main() { |
83c7162d XL |
32 | let foo1 = Foo1 { bar: 1, baz: 2 }; |
33 | match foo1 { | |
34 | Foo1 {bar, baz} => { | |
35 | assert_eq!(bar, 1); | |
36 | assert_eq!(baz, 2); | |
37 | } | |
38 | } | |
39 | ||
40 | let foo2 = Foo2 { bar: 1, baz: 2 }; | |
41 | match foo2 { | |
42 | Foo2 {bar, baz} => { | |
43 | assert_eq!(bar, 1); | |
44 | assert_eq!(baz, 2); | |
45 | } | |
46 | } | |
47 | ||
48 | let foo4 = Foo4C { bar: 1, baz: 2 }; | |
49 | match foo4 { | |
50 | Foo4C {bar, baz} => { | |
970d7e83 LB |
51 | assert_eq!(bar, 1); |
52 | assert_eq!(baz, 2); | |
53 | } | |
54 | } | |
223e47cc | 55 | } |