Bunch'o things
This commit is contained in:
@ -6,10 +6,22 @@ use syn::parse_macro_input;
|
||||
|
||||
struct BlockDerive
|
||||
{
|
||||
block_name: String,
|
||||
input_fields: Vec<Ident>,
|
||||
output_fields: Vec<Ident>,
|
||||
}
|
||||
|
||||
fn get_block_name_func(ctx: &BlockDerive) -> proc_macro2::TokenStream
|
||||
{
|
||||
let block_name = ctx.block_name.as_str();
|
||||
quote! {
|
||||
fn get_block_name(&self) -> &'static str
|
||||
{
|
||||
#block_name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_block_index_func(ctx: &BlockDerive) -> proc_macro2::TokenStream
|
||||
{
|
||||
let inputs = ctx.input_fields.clone();
|
||||
@ -106,23 +118,27 @@ pub fn block_derive(item: TokenStream) -> TokenStream
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let derive = BlockDerive {
|
||||
block_name: input.ident.to_string(),
|
||||
input_fields,
|
||||
output_fields,
|
||||
};
|
||||
|
||||
let set_index_func = set_block_index_func(&derive);
|
||||
let get_successors_func = get_successors_func(&derive);
|
||||
let get_block_name_func = get_block_name_func(&derive);
|
||||
let struct_path = input.ident;
|
||||
let struct_where = input.generics.where_clause.clone();
|
||||
let struct_generics = input.generics;
|
||||
let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
//item
|
||||
quote! {
|
||||
impl #struct_generics ntw_flowgraph::Block for #struct_path #struct_generics
|
||||
#struct_where
|
||||
impl #impl_generics ntw_flowgraph::Block for #struct_path #type_generics
|
||||
#where_clause
|
||||
{
|
||||
#set_index_func
|
||||
#get_successors_func
|
||||
|
||||
// Meta information
|
||||
#get_block_name_func
|
||||
}
|
||||
}
|
||||
.into()
|
||||
|
||||
Reference in New Issue
Block a user