repr_offset/
for_examples_inner.rs
1#![allow(missing_docs)]
2
3use crate::{Aligned, Unaligned};
4
5macro_rules! declare_example_struct {
6 (
7 $(#[$meta:meta])*
8 struct $name:ident;
9 alignment = $alignment:ty,
10 $(impl_GetFieldOffset = $impl_gdo:ident,)?
11 ) => {
12 $(#[$meta])*
13 #[derive(Default)]
14 pub struct $name<A = (),B = (),C = (),D = ()>{
15 pub a:A,
16 pub b:B,
17 pub c:C,
18 pub d:D,
19 }
20
21 impl<A,B,C,D> Copy for $name<A,B,C,D>
22 where
23 A: Copy,
24 B: Copy,
25 C: Copy,
26 D: Copy,
27 {}
28
29 impl<A,B,C,D> Clone for $name<A,B,C,D>
30 where
31 A: Copy,
32 B: Copy,
33 C: Copy,
34 D: Copy,
35 {
36 fn clone(&self)->Self{
37 *self
38 }
39 }
40
41 unsafe_struct_field_offsets!{
42 alignment = $alignment,
43 $(impl_GetFieldOffset = $impl_gdo,)?
44 impl[A,B,C,D] $name<A,B,C,D>{
45 pub const OFFSET_A, a: A;
47 pub const OFFSET_B, b: B;
49 pub const OFFSET_C, c: C;
51 pub const OFFSET_D, d: D;
53 }
54 }
55 };
56}
57
58declare_example_struct! {
59 #[repr(C)]
61 struct ReprC;
62 alignment = Aligned,
63}
64
65declare_example_struct! {
66 #[repr(C)]
70 struct ReprCNoGFO;
71 alignment = Aligned,
72 impl_GetFieldOffset = false,
73}
74
75declare_example_struct! {
76 #[repr(C, align(4))]
78 struct ReprAlign4;
79 alignment = Aligned,
80}
81
82declare_example_struct! {
83 #[repr(C, packed)]
85 struct ReprPacked;
86 alignment = Unaligned,
87}
88
89declare_example_struct! {
90 #[repr(C, packed(2))]
92 struct ReprPacked2;
93 alignment = Unaligned,
94}