authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-10 01:43:07 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-10 01:43:07 -07:00
log02301520811d7796de6e4f87961a44a6f458f702
treea7c673a8ebeaa47ecbb35be8fcfbee2d64c48909
parent2ada45d2e6c295a556cd8092f860630f07caf0d1
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

StructOfArrays: preserve field attributes


1 files changed, 7 insertions(+), 1 deletions(-)

src/StructOfArrays.zig+7-1
...@@ -8,12 +8,18 @@ pub fn StructOfArrays(len: usize, T: type) type {...@@ -8,12 +8,18 @@ pub fn StructOfArrays(len: usize, T: type) type {
8 const fields = info.fields;8 const fields = info.fields;
9 var names: [fields.len][]const u8 = undefined;9 var names: [fields.len][]const u8 = undefined;
10 var types: [fields.len]type = undefined;10 var types: [fields.len]type = undefined;
11 var attrs: [fields.len]std.builtin.Type.StructField.Attributes = undefined;
11 for (fields, 0..) |item, i| {12 for (fields, 0..) |item, i| {
12 names[i] = item.name;13 names[i] = item.name;
13 types[i] = [len]item.type;14 types[i] = [len]item.type;
15 attrs[i] = .{
16 .@"comptime" = item.is_comptime,
17 .@"align" = item.alignment,
18 .default_value_ptr = item.default_value_ptr,
19 };
14 }20 }
15 if (info.is_tuple) return @Tuple(&types);21 if (info.is_tuple) return @Tuple(&types);
16 return @Struct(.auto, null, &names, &types, &@splat(.{}));22 return @Struct(.auto, null, &names, &types, &attrs);
17}23}
1824
19test {25test {