// this function processes the individual fields of the hashable trait macro: derive_hashable
this function processes the individual fields of the hashable trait macro: derive_hashable
this function processes the individual fields of the hashable trait macro : derive_hashable
fn handle_fields_for_hashable(item: &Data) -> proc_macro2::TokenStream {
    match item {
        Data::Struct(ref item) => {
            match item.fields {
                Fields::Named(ref fields) => {
                    let recurse = fields.named.iter().map(|f| {
                        let mut do_we_ignore_field = false;
                        for attr in &f.attrs {
                            match attr.interpret_meta().unwrap() {
                                syn::Meta::NameValue(ref val) => {
                                    if val.ident == "Hashable" {
                                        if let syn::Lit::Str(lit) = &val.lit {
                                            if lit.value() == "Ignore" {
                                                do_we_ignore_field = true;
                                            }
                                        }
                                    }
                                },
                                syn::Meta::List(ref val) => {
                                    // we have more than one property
                                    if val.ident == "Hashable" {
                                        // we have a hash command here, lets search for the sub command
                                        for nestedmeta in val.nested.iter() {
                                            if let syn::NestedMeta::Meta(syn::Meta::Word(ref val)) = nestedmeta {
                                                if val == "Ignore" {
                                                    do_we_ignore_field = true;
                                                }
                                            }
                                        }
                                    }
                                },
                                _ => (),
                            };
                        }
                        if !do_we_ignore_field {
                            let name = &f.ident;
                            quote_spanned! {f.span()=>
                                (&self.#name).append_raw_bytes(&mut buf);
                            }
                        } else {
                            quote_spanned! {f.span()=>
                            }
                        }
                    });
                    quote! {#( #recurse)*
                    }
                },
                Fields::Unnamed(ref fields) => {
                    let recurse = fields.unnamed.iter().enumerate().map(|(i, f)| {
                        let index = Index::from(i);
                        quote_spanned! {f.span()=>
                            (&self.#index).append_raw_bytes(&mut buf);
                        }
                    });
                    quote! {
                         #( #recurse)*
                    }
                },
                Fields::Unit => {
                    // dont hash units
                    quote!(0)
                },
            }
        },
        // have not yet implemented enums and unions
        Data::Enum(_) | Data::Union(_) => unimplemented!(),
    }
}
fn handle_fields_for_hashable ( item : & Data ) -> proc_macro2 :: TokenStream { match item { Data :: Struct ( ref item ) => { match item . fields { Fields :: Named ( ref fields ) => { let recurse = fields . named . iter ( ) . map ( | f | { let mut do_we_ignore_field = false ; for attr in & f . attrs { match attr . interpret_meta ( ) . unwrap ( ) { syn :: Meta :: NameValue ( ref val ) => { if val . ident == " " { if let syn :: Lit :: Str ( lit ) = & val . lit { if lit . value ( ) == " " { do_we_ignore_field = true ; } } } } , syn :: Meta :: List ( ref val ) => { // we have more than one property if val . ident == " " { // we have a hash command here, lets search for the sub command for nestedmeta in val . nested . iter ( ) { if let syn :: NestedMeta :: Meta ( syn :: Meta :: Word ( ref val ) ) = nestedmeta { if val == " " { do_we_ignore_field = true ; } } } } } , _ => ( ) , } ; } if ! do_we_ignore_field { let name = & f . ident ; quote_spanned ! { f span ( ) ( self name ) append_raw_bytes ( mut buf ) } } else { quote_spanned ! { f span ( ) } } } ) ; quote ! { ( recurse ) } } , Fields :: Unnamed ( ref fields ) => { let recurse = fields . unnamed . iter ( ) . enumerate ( ) . map ( | ( i , f ) | { let index = Index :: from ( i ) ; quote_spanned ! { f span ( ) ( self index ) append_raw_bytes ( mut buf ) } } ) ; quote ! { ( recurse ) } } , Fields :: Unit => { // dont hash units quote ! ( 0 ) } , } } , // have not yet implemented enums and unions Data :: Enum ( _ ) | Data :: Union ( _ ) => unimplemented ! ( ) , } }
this function processes the individual fields of the hashable trait macro: derive_hashable
this function processes the individual fields of the hashable trait macro : derive_hashable
item
&Data