Assume we have a Person
struct and a PersonName
struct that used by a field, like the following:
struct Person {
name: PersonName,
age: u8,
}
struct PersonName {
name: String,
middle_name: Option<String>,
surname: Option<String>,
}
Create the struct:
let foo = Person { name: PersonName{name: String::from("bar"), middle_name: None, surname: String::from("baz") }, age: 16u8 };
How can I use this string to gain access to the struct field specified in it?
let foo_surname = eval("name.surname") // returns "baz"
// struct evaluator returns the value of specific field
// i.e.: field_path: "my_struct_field.sub_field1.sub_sub_field_1"
fn eval(field_path: String) -> ...{}
Is there any way to do this without writing a custom evaluator?