Hi, I'm using quote to generate struct for fields with Vec<String> as type, there's an error for the following code:
fn make_ident(s: &str) -> Ident {
syn::Ident::new(s, s.span())
}
fn main() {
let mut code = quote!();
#[allow(nonstandard_style)]
let struct_name = "MyStruct";
let (field, typ) = ("Name", "Vec<String>");
let struct_name = make_ident(struct_name);
let field = make_ident(&field);
let typ = make_ident(&typ);
code.extend(quote! {
struct #struct_name {
// TODO: iter all field
#field: #typ,
}
});
}
The error shows:
thread 'main' panicked at '"Vec<String>" is not a valid Ident',
What is correct way to generate struct's fields with type Vec<String> or HashMap<String, String>?
Hi, I'm using
quote
to generatestruct
for fields withVec<String>
as type, there's an error for the following code:The error shows:
What is correct way to generate struct's fields with type
Vec<String>
orHashMap<String, String>
?Thanks