diff --git a/Cargo.toml b/Cargo.toml index c0a63a7..977a81c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leptos-struct-table-macro" -version = "0.9.1" +version = "0.10.0" edition = "2021" authors = ["Marc-Stefan Cassola"] description = "Macros for the leptos-struct-table crate." diff --git a/src/table_row.rs b/src/table_row.rs index 74f467d..fdad33a 100644 --- a/src/table_row.rs +++ b/src/table_row.rs @@ -367,7 +367,6 @@ fn get_data_provider_logic( }; quote! { - #[async_trait::async_trait(?Send)] impl #generic_params TableDataProvider<#ident> for Vec<#ident> #where_clause { @@ -414,9 +413,11 @@ impl ToTokens for TableRowDeriveInput { let mut titles = vec![]; let mut cells = vec![]; + let mut col_name_match_arms = vec![]; for f in &fields { let name = f.ident.as_ref().expect("named field"); + let name_str = name.to_string(); if f.skip { continue; @@ -427,7 +428,7 @@ impl ToTokens for TableRowDeriveInput { } else if let Some(ref t) = f.title { t.clone() } else { - name.to_string().to_title_case() + name_str.to_title_case() }; let head_class = f.head_class(); @@ -442,6 +443,8 @@ impl ToTokens for TableRowDeriveInput { quote! { on_click=|_| () } }; + col_name_match_arms.push(quote! {#index => #name_str,}); + titles.push(quote! { <#thead_cell_renderer class=leptos::Signal::derive(move || class_provider.thead_cell(leptos_struct_table::get_sorting_for_column(#index, sorting), #head_class)) @@ -515,6 +518,13 @@ impl ToTokens for TableRowDeriveInput { #(#titles)* } } + + fn col_name(col_index: usize) -> &'static str { + match col_index { + #(#col_name_match_arms)* + _ => unreachable!("Column index {} out of bounds", col_index), + } + } } }); }