Last active
May 12, 2024 17:09
-
-
Save softprops/92c1c09dfe0ca6869c2e583fc51fa3b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const meta = std.meta; | |
const Example = struct { | |
foo: []const u8, | |
bar: i32, | |
const docs = std.EnumArray( | |
meta.FieldEnum(Example), | |
// π type of value of metadata checked at comptime, can be any type declared | |
[]const u8, | |
).init( | |
.{ | |
.foo = "foo will do a thing", | |
.bar = "bar will do this other thing", | |
//π will fail at comptime if struct field is omitted here declared here but not in struct | |
//.otherfield | |
}, | |
); | |
}; | |
pub fn main() void { | |
std.debug.print( | |
"{s}", | |
//π will fail at comptime if passed invalid field ref | |
.{Example.docs.get(.baz)}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment