Files
ziglings/patches/patches/082_anonymous_structs3.patch
2026-02-27 13:09:54 +01:00

33 lines
985 B
Diff

--- exercises/082_anonymous_structs3.zig 2026-02-27 13:05:46
+++ answers/082_anonymous_structs3.zig 2026-02-27 13:07:22
@@ -82,14 +82,14 @@
// @typeInfo(Circle).@"struct".fields
//
// This will be an array of StructFields.
- const fields = ???;
+ const fields = @typeInfo(@TypeOf(tuple)).@"struct".fields;
// 2. Loop through each field. This must be done at compile
// time.
//
// Hint: remember 'inline' loops?
//
- for (fields) |field| {
+ inline for (fields) |field| {
// 3. Print the field's name, type, and value.
//
// Each 'field' in this loop is one of these:
@@ -123,9 +123,9 @@
// for declarations. If it's a value, it looks for data.
//
print("\"{s}\"({any}):{any} ", .{
- field.???,
- field.???,
- ???,
+ field.name,
+ field.type,
+ @field(tuple, field.name),
});
}
}