Is there a way to access the TypeId
(std::any::TypeId::of::<T>
) of a struct member by name?
If I have a basic struct:
MyStruct {
value: i64,
}
And I only know MyStruct
and value
, is there a way to access TypeId::of::<i64>
- where i64
depends on the type of value
?
main () {
assert_eq!(
TypeId::of::<i64>,
// ^^^ this works
type_id_of!(MyStruct, value),
// ^^^ this is what I'm looking for
);
}
See related question: Is it possible to access the type of a struct member for function signatures or declarations?