1 #![allow(
2 dead_code,
3 non_snake_case,
4 non_camel_case_types,
5 non_upper_case_globals
6 )]
7
8 /// <div rustbindgen opaque></div>
9 #[repr(C)]
10 #[repr(align(4))]
11 #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
12 pub struct OtherOpaque {
13 pub _bindgen_opaque_blob: u32,
14 }
15 #[test]
bindgen_test_layout_OtherOpaque()16 fn bindgen_test_layout_OtherOpaque() {
17 assert_eq!(
18 ::std::mem::size_of::<OtherOpaque>(),
19 4usize,
20 concat!("Size of: ", stringify!(OtherOpaque))
21 );
22 assert_eq!(
23 ::std::mem::align_of::<OtherOpaque>(),
24 4usize,
25 concat!("Alignment of ", stringify!(OtherOpaque))
26 );
27 }
28 /// <div rustbindgen opaque></div>
29 #[repr(C)]
30 #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
31 pub struct Opaque {
32 pub _address: u8,
33 }
34 #[repr(C)]
35 #[derive(Debug, Copy, Clone, Hash, PartialEq)]
36 pub struct WithOpaquePtr {
37 pub whatever: *mut u8,
38 pub other: u32,
39 pub t: OtherOpaque,
40 }
41 #[test]
bindgen_test_layout_WithOpaquePtr()42 fn bindgen_test_layout_WithOpaquePtr() {
43 const UNINIT: ::std::mem::MaybeUninit<WithOpaquePtr> =
44 ::std::mem::MaybeUninit::uninit();
45 let ptr = UNINIT.as_ptr();
46 assert_eq!(
47 ::std::mem::size_of::<WithOpaquePtr>(),
48 16usize,
49 concat!("Size of: ", stringify!(WithOpaquePtr))
50 );
51 assert_eq!(
52 ::std::mem::align_of::<WithOpaquePtr>(),
53 8usize,
54 concat!("Alignment of ", stringify!(WithOpaquePtr))
55 );
56 assert_eq!(
57 unsafe {
58 ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize
59 },
60 0usize,
61 concat!(
62 "Offset of field: ",
63 stringify!(WithOpaquePtr),
64 "::",
65 stringify!(whatever)
66 )
67 );
68 assert_eq!(
69 unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize },
70 8usize,
71 concat!(
72 "Offset of field: ",
73 stringify!(WithOpaquePtr),
74 "::",
75 stringify!(other)
76 )
77 );
78 assert_eq!(
79 unsafe { ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize },
80 12usize,
81 concat!(
82 "Offset of field: ",
83 stringify!(WithOpaquePtr),
84 "::",
85 stringify!(t)
86 )
87 );
88 }
89 impl Default for WithOpaquePtr {
default() -> Self90 fn default() -> Self {
91 let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
92 unsafe {
93 ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
94 s.assume_init()
95 }
96 }
97 }
98