field_types
field_types copied to clipboard
Can you use these enums to address fields on a struct during runtime?
If not... will you ever be able to?
struct Foo {
bar: usize,
}
...
let foo = Foo { bar: 1 };
for member in Foo::as_field_name_array() {
foo[member] = 2;
}
No, this isn’t possible on Rust – not with index access (foo[member]
). There are some other crates that allow addressing struct fields dynamically though.