Remove some unnecessary clones in the GBNF derive macro.
This commit is contained in:
parent
1e80ae508e
commit
f7df8af068
|
@ -37,26 +37,22 @@ fn generate_gbnf(input: TokenStream, create_struct: bool) -> TokenStream {
|
|||
// run, and then shove the resulting GBNF rule into the type as a
|
||||
// static string.
|
||||
|
||||
if let Ok(expr_struct) = syn::parse::<GbnfStructDef>(input.clone()) {
|
||||
if let Ok(expr_struct) = syn::parse::<GbnfStructDef>(input) {
|
||||
let struct_name_str = LitStr::new(&expr_struct.name.to_string(), Span::call_site().into());
|
||||
let struct_name = expr_struct.name;
|
||||
let fields = expr_struct.fields.iter();
|
||||
|
||||
let gbnfs: Vec<_> = expr_struct
|
||||
.fields
|
||||
.iter()
|
||||
.map(|field| {
|
||||
let gbnfs = expr_struct.fields.iter().map(|field| {
|
||||
let field_type = &field.ty;
|
||||
let field_ident = field
|
||||
.ident
|
||||
.clone()
|
||||
.as_ref()
|
||||
.map(|i| i.to_string())
|
||||
.map(|field_name| LitStr::new(&field_name, Span::call_site().into()))
|
||||
.expect("no ident");
|
||||
|
||||
quote! { gbnf_field!(#field_ident, #field_type) }
|
||||
})
|
||||
.collect();
|
||||
});
|
||||
|
||||
let struct_frag = if create_struct {
|
||||
quote! {
|
||||
|
@ -95,7 +91,6 @@ fn generate_gbnf(input: TokenStream, create_struct: bool) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Create a GBNF complex type as a Rust struct.
|
||||
#[proc_macro]
|
||||
pub fn gbnf_complex(input: TokenStream) -> TokenStream {
|
||||
|
|
Loading…
Reference in New Issue