of_field

Macro of_field 

Source
macro_rules! of_field {
    ($ty:ident :: $field:ident) => { ... };
    (<$ty:ty> :: $field:ident) => { ... };
}
Expand description

Get the name of the given struct field like Type::field as a String.

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.

This macro checks that the field exists on the given type. If either the type or field is renamed via refactoring tools, the macro call will be updated accordingly.

ยง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");