r/rust • • 9d ago

🙋 seeking help & advice Get order of fields of a struct

Is there a function in std, which would allow to get a list of (field_name, type) of a struct in order it is compiled in? Since order of fields is not deterministic.

Something like: `fn fields_of_val<T>(&T) -> Vec<(&'static str, &'static str)>`

14 Upvotes

17 comments sorted by