fn generate_getter_trait(expr_lit: &syn::ExprLit) -> proc_macro2::TokenStream {
    if let Lit::Str(tag_index) = &expr_lit.lit {
        //argument is exactly one literal
        let fn_name = tag_index.value().to_snake_case().to_ident();
        let fn_stream = quote! (
            fn #fn_name(&'a self) -> std::option::Option<&'a str>{
                self.tags().get(#tag_index)
            }
        );
        wrap_in_trait(&fn_stream, tag_index)
    } else {
        // using quote_spanned while throwing an error lets us specify which part of the expression should be underlined red
        quote_spanned!(expr_lit.span()=> compile_error!("Each argument has to begin with a string literal specifying the tag index."))
    }
}
/// Takes an individual argument that must only consist of one String literal, and returns the corresponding getter function.
Takes an individual argument that must only consist of one String literal, and returns the corresponding getter function.
Takes an individual argument that must only consist of one String literal and returns the corresponding getter function .
fn generate_getter_trait(expr_lit: &syn::ExprLit) -> proc_macro2::TokenStream {
    if let Lit::Str(tag_index) = &expr_lit.lit {
        //argument is exactly one literal
        let fn_name = tag_index.value().to_snake_case().to_ident();
        let fn_stream = quote! (
            fn #fn_name(&'a self) -> std::option::Option<&'a str>{
                self.tags().get(#tag_index)
            }
        );
        wrap_in_trait(&fn_stream, tag_index)
    } else {
        // using quote_spanned while throwing an error lets us specify which part of the expression should be underlined red
        quote_spanned!(expr_lit.span()=> compile_error!("Each argument has to begin with a string literal specifying the tag index."))
    }
}
fn generate_getter_trait ( expr_lit : & syn :: ExprLit ) -> proc_macro2 :: TokenStream { if let Lit :: Str ( tag_index ) = & expr_lit . lit { //argument is exactly one literal let fn_name = tag_index . value ( ) . to_snake_case ( ) . to_ident ( ) ; let fn_stream = quote ! ( fn fn_name ( ' a self ) std option Option ' a str { self tags ( ) get ( tag_index ) } ) ; wrap_in_trait ( & fn_stream , tag_index ) } else { // using quote_spanned while throwing an error lets us specify which part of the expression should be underlined red quote_spanned ! ( expr_lit span ( ) compile_error ( " " ) ) } }
Takes an individual argument that must only consist of one String literal, and returns the corresponding getter function.
Takes an individual argument that must only consist of one String literal and returns the corresponding getter function .
expr_lit
&syn::ExprLit
expr_lit
&syn::ExprLit