#[derive(FieldName)]Expand description
为结构体的每个字段生成对应获取的字段名的方法 (字符串字面量)
方法名为 field_{field_name}, 返回类型为 &'static str(如 field_name), 值为字段的原始名称(如 "name").
§示例
#[derive(FieldName)]
struct Person {
name: String,
age: u32,
}
impl Person {
pub fn field_name() -> &'static str {
"name"
}
pub fn field_age() -> &'static str {
"age"
}
}Method for generating corresponding field names for each field of a structure (string literal)
The method name is’ field_ {field_name} ‘, the return type is’ static str’ (such as’ field_name ‘), and the value is the original name of the field (such as’ name’)
§Example
#[derive(FieldName)]
struct Person {
name: String,
age: u32,
}
impl Person {
pub fn field_name() -> &'static str {
"name"
}
pub fn field_age() -> &'static str {
"age"
}
}