I'm trying to parse a struct at comptime. Some of the fields will be set as a []const u8 with a default value. How do I go about casting the default_value into a []const u8?
const foo = struct {
comptime description: []const u8 = "Some description",
};
fn parseStruct(comptime T: type) []const u8 {
// I will be parsing the other fields but not important for question
const field = @typeInfo(T).Struct.fields[0];
if (field.type == []const u8) {
const should_be_a_string: *const anyopaque = field.default_value orelse "";
return should_be_a_string;
} else {
return "";
}
}
fn main() void {
std.debug.print("{s}", .{parseStruct(foo)})
}