我想生成一个HashMap使用结构字段作为键,并使用usize整数作为值。
pub struct Article {
title: String,
content: String,
category: String,
comments: Vec<Comment>
}
pub struct Comment {
content: String
}
我的预期输出是:
{
title: 0,
content: 1,
category: 2
comments[].content: 3
}
我的解决方案是impl我FieldsMapping对Article和的特点Comment:
pub trait FieldsMapping {
fn get_fields_map(&self) -> HashMap<String, usize>;
}
我想为自定义派生编写一个编译器插件FieldsMapping。
我的问题是:如何获取编译器插件中的所有字段?我怎么知道字段类型是Vec什么?