pub fn compute_struct_layout(
name: &str,
fields: &[(String, FieldType)],
) -> StructLayoutExpand description
Compute the repr(C) struct layout for a named type with the given fields.
The layout follows C struct rules:
- An 8-byte v2 heap header occupies bytes
[0, 8). - Fields are placed sequentially after the header, each aligned to its natural alignment (inserting padding bytes as needed).
- The total size is padded to the struct’s overall alignment (the maximum alignment of the header and all fields).
§Examples
use shape_value::v2_struct_layout::{compute_struct_layout, FieldType};
let layout = compute_struct_layout("Point", &[
("x".into(), FieldType::F64),
("y".into(), FieldType::F64),
]);
assert_eq!(layout.fields[0].offset, 8); // after 8-byte header
assert_eq!(layout.fields[1].offset, 16);
assert_eq!(layout.total_size, 24);