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
use TokenStream;
use parse_macro_input;
/// Marks a struct as a representation of a C-style struct with memory-mapped fields.
///
/// # Supported Attributes:
/// - `size = "<struct size>"`
/// Defines the total memory size of the struct.
/// Structs attributed with size will implement the `SizedViewable` trait and be `Copy`able.
///
/// - `resolver = "my_resolver_fn"`
/// Define a custom offset resolver where the raw field attribute value of `offset` will be passed into.
/// This allows a relaxiation of the `offset` value of the field as it may be anything. The function must return an u64.
/// By default the resolver is `core::convert::identity`.
///
/// Each field within the struct must be annotated with the `#[field(...)]` attribute.
///
/// # `#[field(...)]` Attributes:
/// - `offset = "<field offset>"` (required)
/// Specifies the memory offset of the field within the struct.
/// This can be either a fixed value (e.g., `0x08`) or a function call (e.g., `get_offset_field_a()`).
/// **Note:** If a function call is used, the function will be executed each time the getter is invoked
/// to determine the field's offset.
///
/// # Example:
/// ```ignore
/// #[raw_struct(size = 0x10)]
/// struct MyStruct {
/// #[field(offset = 0x00)]
/// pub field_a: u32,
///
/// #[field(offset = 0x04)]
/// pub field_b: u32,
///
/// #[field(offset = 0x08)]
/// pub field_c: [u8; 0x8],
/// }
/// ```