fn visit_fields(
    fields: &syn::Fields,
    dont_visit: bool,
) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) {
    // Generate a destructuring pattern that assigns predictable names to all
    // fields.
    let mut names = vec![];
    let pat = match fields {
        syn::Fields::Named(ref fields) => {
            let mut mapping = vec![];
            for (i, field) in fields.named.iter().enumerate() {
                let field_name = &field.ident;
                let name = format_ident!("arg{}", i);
                if !dont_visit && !has_dont_visit(&field.attrs) {
                    names.push(name.clone());
                }
                mapping.push(quote! {
                    #field_name: #name
                });
            }
            quote! { {#(#mapping),*} }
        }
        syn::Fields::Unnamed(ref fields) => {
            let mut mapping = vec![];
            for (i, field) in fields.unnamed.iter().enumerate() {
                let name = format_ident!("arg{}", i);
                if !dont_visit && !has_dont_visit(&field.attrs) {
                    names.push(name.clone());
                }
                mapping.push(name);
            }
            quote! { (#(#mapping),*) }
        }
        syn::Fields::Unit => {
            quote! {}
        }
    };

    // Generate the visit calls for the names that we do not skip or ignore.
    (
        quote! {
            #pat => {
                #(#names.walk(visitor);)*
            }
        },
        quote! {
            #pat => {
                #(#names.for_each_node(each);)*
            }
        },
    )
}
/// Generate the code to visit fields in a struct-like item.
Generate the code to visit fields in a struct-like item.
Generate the code to visit fields in a struct - like item .
fn visit_fields(
    fields: &syn::Fields,
    dont_visit: bool,
) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) {
    // Generate a destructuring pattern that assigns predictable names to all
    // fields.
    let mut names = vec![];
    let pat = match fields {
        syn::Fields::Named(ref fields) => {
            let mut mapping = vec![];
            for (i, field) in fields.named.iter().enumerate() {
                let field_name = &field.ident;
                let name = format_ident!("arg{}", i);
                if !dont_visit && !has_dont_visit(&field.attrs) {
                    names.push(name.clone());
                }
                mapping.push(quote! {
                    #field_name: #name
                });
            }
            quote! { {#(#mapping),*} }
        }
        syn::Fields::Unnamed(ref fields) => {
            let mut mapping = vec![];
            for (i, field) in fields.unnamed.iter().enumerate() {
                let name = format_ident!("arg{}", i);
                if !dont_visit && !has_dont_visit(&field.attrs) {
                    names.push(name.clone());
                }
                mapping.push(name);
            }
            quote! { (#(#mapping),*) }
        }
        syn::Fields::Unit => {
            quote! {}
        }
    };
    // Generate the visit calls for the names that we do not skip or ignore.
    (
        quote! {
            #pat => {
                #(#names.walk(visitor);)*
            }
        },
        quote! {
            #pat => {
                #(#names.for_each_node(each);)*
            }
        },
    )
}
fn visit_fields ( fields : & syn :: Fields , dont_visit : bool , ) -> ( proc_macro2 :: TokenStream , proc_macro2 :: TokenStream ) { // Generate a destructuring pattern that assigns predictable names to all // fields. let mut names = vec ! [ ] ; let pat = match fields { syn :: Fields :: Named ( ref fields ) => { let mut mapping = vec ! [ ] ; for ( i , field ) in fields . named . iter ( ) . enumerate ( ) { let field_name = & field . ident ; let name = format_ident ! ( " " i ) ; if ! dont_visit && ! has_dont_visit ( & field . attrs ) { names . push ( name . clone ( ) ) ; } mapping . push ( quote ! { field_name name } ) ; } quote ! { { ( mapping ) } } } syn :: Fields :: Unnamed ( ref fields ) => { let mut mapping = vec ! [ ] ; for ( i , field ) in fields . unnamed . iter ( ) . enumerate ( ) { let name = format_ident ! ( " " i ) ; if ! dont_visit && ! has_dont_visit ( & field . attrs ) { names . push ( name . clone ( ) ) ; } mapping . push ( name ) ; } quote ! { ( ( mapping ) ) } } syn :: Fields :: Unit => { quote ! { } } } ; // Generate the visit calls for the names that we do not skip or ignore. ( quote ! { pat { ( names walk ( visitor ) ) } } , quote ! { pat { ( names for_each_node ( each ) ) } } , ) }
Generate the code to visit fields in a struct-like item.
Generate the code to visit fields in a struct - like item .
fields
&syn::Fields
dont_visit
bool
fields
&syn::Fields
dont_visit
bool