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