Skip to content

Commit

Permalink
removed async-trait and impl TableRow::col_name
Browse files Browse the repository at this point in the history
  • Loading branch information
maccesch committed Feb 22, 2024
1 parent a2736b0 commit e8de1ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
14 changes: 12 additions & 2 deletions src/table_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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))
Expand Down Expand Up @@ -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),
}
}
}
});
}
Expand Down

0 comments on commit e8de1ab

Please sign in to comment.