field_types icon indicating copy to clipboard operation
field_types copied to clipboard

Can you use these enums to address fields on a struct during runtime?

Open hcldan opened this issue 2 years ago • 1 comments

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;
}

hcldan avatar Nov 03 '22 12:11 hcldan

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.

jirutka avatar Jan 05 '23 22:01 jirutka