I am looking to dynamically set a structs field based on a string.
I have a project (physics simulator) that is configured at runtime via a json.
One of the elements, is initialized with a get field and a set field, and Id like to be able to mutably access a struct field based on these strings.
I tried using @field and std.meta methods but unfortunatly, the get_field is configured at runtime and thus fails to evaluate at comptime.
self.get_val = switch (self.connection_getter.?){
inline else => |impl| @field(impl, self.get_field)
};
switch (self.connection_setter.?){
inline else => |impl| @field(impl, self.set_field) = self.set_val
}
Is there a good way to map strings to struct fields? If that string is not accessible at comptime?