// this is the actual code for the derive macro, the function in lib points to this one
this is the actual code for the derive macro, the function in lib points to this one
this is the actual code for the derive macro the function in lib points to this one
pub fn create_derive_hashable(input: DeriveInput) -> proc_macro2::TokenStream {
    let object_name = &input.ident;
    let mut digest = None;
    for attr in &input.attrs {
        if let syn::Meta::NameValue(val) = attr.interpret_meta().unwrap() {
            if val.ident == "digest" {
                if let syn::Lit::Str(lit) = &val.lit {
                    digest = Some(lit.value());
                }
            }
        }
    }
    let item = input.data;
    let fields_text = handle_fields_for_hashable(&item);
    let digest = digest.expect("Could not find Digest attribute"); // this is for the error, if the Digest was not given, this error message will be displayed
    let varname = Ident::new(&digest, Span::call_site());
    let gen = quote! {
        impl  Hashable for #object_name  {
            fn hash(&self) -> Vec<u8> {
                let mut hasher = <#varname>::new();
                let mut buf:Vec<u8> = Vec::new();
                #fields_text
                hasher.input(&buf);
                hasher.result().to_vec()
            }
        }
    };
    gen
}
pub fn create_derive_hashable ( input : DeriveInput ) -> proc_macro2 :: TokenStream { let object_name = & input . ident ; let mut digest = None ; for attr in & input . attrs { if let syn :: Meta :: NameValue ( val ) = attr . interpret_meta ( ) . unwrap ( ) { if val . ident == " " { if let syn :: Lit :: Str ( lit ) = & val . lit { digest = Some ( lit . value ( ) ) ; } } } } let item = input . data ; let fields_text = handle_fields_for_hashable ( & item ) ; let digest = digest . expect ( " " ) ; // this is for the error, if the Digest was not given, this error message will be displayed let varname = Ident :: new ( & digest , Span :: call_site ( ) ) ; let gen = quote ! { impl Hashable for object_name { fn hash ( self ) Vec u8 { let mut hasher varname new ( ) let mut buf Vec u8 Vec new ( ) fields_text hasher input ( buf ) hasher result ( ) to_vec ( ) } } } ; gen }
this is the actual code for the derive macro, the function in lib points to this one
this is the actual code for the derive macro the function in lib points to this one
input
DeriveInput