microrm-macros 0.6.3

Procedural macro implementations for the microrm crate.
Documentation
use convert_case::{Case, Casing};
use proc_macro::TokenStream;
use quote::{format_ident, quote, ToTokens};

pub fn index_cols(tokens: TokenStream) -> TokenStream {
    type MT = syn::punctuated::Punctuated<syn::ExprPath, syn::token::Comma>;
    let paths = syn::parse_macro_input!(tokens with MT::parse_terminated);

    let mut part_list = proc_macro2::TokenStream::new();

    let entity_path = {
        let mut epath = paths.first().unwrap().clone();
        epath.path.segments.pop();
        let v = epath.path.segments.pop().unwrap().into_value();
        epath.path.segments.push(v);
        epath
    };

    for mut path in paths.into_iter() {
        let last_seg = path.path.segments.last_mut().unwrap();
        last_seg.ident = format_ident!(
            "_{}_INDEX",
            last_seg.ident.to_string().to_case(Case::UpperSnake)
        );

        quote! { ::microrm::schema::index::IndexSignifier< { #path } > , }
            .to_tokens(&mut part_list);
    }

    quote! { <#entity_path as ::microrm::schema::index::IndexPartList<#entity_path,(#part_list)>>::PartList }.into()
}