pub fn irc_tags(
    attr: proc_macro::TokenStream,
    item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
    // parse attribute into list of tags
    let tags = parse_macro_input!(attr with Punctuated::<Expr, Token![,]>::parse_terminated);

    // get name of the struct that the tags will be added to
    let struct_def = item.clone();
    let message_struct = parse_macro_input!(struct_def as syn::ItemStruct);
    let struct_ident = message_struct.ident;

    // Implement trait for each argument
    let trait_impls: Vec<proc_macro2::TokenStream> = match tags
        .iter()
        .map(lit_str_from_tag_expr)
        .collect::<Result<Vec<_>, _>>()
    {
        Ok(lit_str_vec) => lit_str_vec
            .into_iter()
            .map(trait_name_from_tag_index)
            .map(|tag_trait| {
                // importing each trait individually should give us better error messages if a tag was inserted that does not exist
                // we import the trait under a different name so that there aren't any conflicting definitions with already defined traits
                let safe_tag_trait = quote::format_ident!("__Macro{}", tag_trait);
                quote!(
                        use crate::messages::tags::#tag_trait as #safe_tag_trait;
                        impl<'a> #safe_tag_trait<'a> for #struct_ident<'a> {}
                )
            })
            .collect(),
        Err(err_msg) => return err_msg.into(),
    };

    // add implementation of all necessary traits after struct definition
    let struct_def: proc_macro2::TokenStream = item.into();
    quote!(
        #struct_def

        #(#trait_impls)*
    )
    .into()
}
/// Implements tags for an associated struct. Only tags initialized with `generate_tag_traits` can be implemented.
Implements tags for an associated struct. Only tags initialized with `generate_tag_traits` can be implemented.
Implements tags for an associated struct . Only tags initialized with ` generate_tag_traits ` can be implemented .
pub fn irc_tags(
    attr: proc_macro::TokenStream,
    item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
    // parse attribute into list of tags
    let tags = parse_macro_input!(attr with Punctuated::<Expr, Token![,]>::parse_terminated);
    // get name of the struct that the tags will be added to
    let struct_def = item.clone();
    let message_struct = parse_macro_input!(struct_def as syn::ItemStruct);
    let struct_ident = message_struct.ident;
    // Implement trait for each argument
    let trait_impls: Vec<proc_macro2::TokenStream> = match tags
        .iter()
        .map(lit_str_from_tag_expr)
        .collect::<Result<Vec<_>, _>>()
    {
        Ok(lit_str_vec) => lit_str_vec
            .into_iter()
            .map(trait_name_from_tag_index)
            .map(|tag_trait| {
                // importing each trait individually should give us better error messages if a tag was inserted that does not exist
                // we import the trait under a different name so that there aren't any conflicting definitions with already defined traits
                let safe_tag_trait = quote::format_ident!("__Macro{}", tag_trait);
                quote!(
                        use crate::messages::tags::#tag_trait as #safe_tag_trait;
                        impl<'a> #safe_tag_trait<'a> for #struct_ident<'a> {}
                )
            })
            .collect(),
        Err(err_msg) => return err_msg.into(),
    };
    // add implementation of all necessary traits after struct definition
    let struct_def: proc_macro2::TokenStream = item.into();
    quote!(
        #struct_def
        #(#trait_impls)*
    )
    .into()
}
pub fn irc_tags ( attr : proc_macro :: TokenStream , item : proc_macro :: TokenStream , ) -> proc_macro :: TokenStream { // parse attribute into list of tags let tags = parse_macro_input ! ( attr with Punctuated Expr Token [ ] parse_terminated ) ; // get name of the struct that the tags will be added to let struct_def = item . clone ( ) ; let message_struct = parse_macro_input ! ( struct_def as syn ItemStruct ) ; let struct_ident = message_struct . ident ; // Implement trait for each argument let trait_impls : Vec < proc_macro2 :: TokenStream > = match tags . iter ( ) . map ( lit_str_from_tag_expr ) . collect :: < Result < Vec < _ > , _ > > ( ) { Ok ( lit_str_vec ) => lit_str_vec . into_iter ( ) . map ( trait_name_from_tag_index ) . map ( | tag_trait | { // importing each trait individually should give us better error messages if a tag was inserted that does not exist // we import the trait under a different name so that there aren't any conflicting definitions with already defined traits let safe_tag_trait = quote :: format_ident ! ( " " tag_trait ) ; quote ! ( use crate messages tags tag_trait as safe_tag_trait impl ' a safe_tag_trait ' a for struct_ident ' a { } ) } ) . collect ( ) , Err ( err_msg ) => return err_msg . into ( ) , } ; // add implementation of all necessary traits after struct definition let struct_def : proc_macro2 :: TokenStream = item . into ( ) ; quote ! ( struct_def ( trait_impls ) ) . into ( ) }
Implements tags for an associated struct.
Implements tags for an associated struct .
attr
proc_macro::TokenStream
item
proc_macro::TokenStream
attr
proc_macro::TokenStream
item
proc_macro::TokenStream