mirror of
https://codeberg.org/ziglings/exercises.git
synced 2024-12-26 09:30:31 +00:00
32 lines
1,011 B
Diff
32 lines
1,011 B
Diff
--- exercises/082_anonymous_structs3.zig 2024-09-07 19:13:58.210327580 +0200
|
|
+++ answers/082_anonymous_structs3.zig 2024-09-07 19:21:20.972733477 +0200
|
|
@@ -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:
|
|
@@ -117,9 +117,9 @@
|
|
//
|
|
// The first field should print as: "0"(bool):true
|
|
print("\"{s}\"({any}):{any} ", .{
|
|
- field.???,
|
|
- field.???,
|
|
- ???,
|
|
+ field.name,
|
|
+ field.type,
|
|
+ @field(tuple, field.name),
|
|
});
|
|
}
|
|
}
|