macro_rules! of_field {
(Self:: $field:ident) => { ... };
($ty:ident :: $field:ident) => { ... };
(<$ty:ty> :: $field:ident) => { ... };
}Expand description
Get the name of the given struct field like Type::field as a &'static str.
This macro resolves Self to the appropriate type when used inside an impl block.
By default, this macro expects a simple type identifier like Type::field. To use
types with qualified path or generic parameters, wrap the type in angle brackets
like <Type<T>>::field or <module::Type>::field.
ยงExamples
struct MyStruct {
my_field: u32,
}
struct MyGenericStruct<T> {
my_field: T,
}
assert_eq!(pretty_name::of_field!(MyStruct::my_field), "MyStruct::my_field");
assert_eq!(pretty_name::of_field!(<MyGenericStruct<u32>>::my_field), "<MyGenericStruct<u32>>::my_field");