Skip to content

Commit 9042b90

Browse files
committed
chore: rustfmt + clippy
1 parent 9a43d85 commit 9042b90

4 files changed

Lines changed: 34 additions & 48 deletions

File tree

src/class_providers/tailwind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl TableClassesProvider for TailwindClassesPreset {
3333
}
3434

3535
fn row(&self, row_index: usize, selected: bool, template_classes: &str) -> String {
36-
let bg_color = if row_index % 2 == 0 {
36+
let bg_color = if row_index.is_multiple_of(2) {
3737
if selected {
3838
"bg-sky-300 text-gray-700 dark:bg-sky-700 dark:text-gray-400"
3939
} else {

src/components/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::table_row::TableRow;
21
use crate::EventHandler;
2+
use crate::table_row::TableRow;
33
use leptos::prelude::*;
44

55
/// The default table row renderer. Uses the `<tr>` element. Please note that this

src/components/table_content.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,19 +508,19 @@ where
508508
return;
509509
}
510510

511-
if let Ok((_, loaded_range)) = &result {
512-
if loaded_range.end < missing_range.end {
513-
match row_count_opt {
514-
// Use pre-fetched value!
515-
Some(row_count) => {
516-
if loaded_range.end < row_count {
517-
set_known_row_count(loaded_range.end);
518-
}
519-
}
520-
None => {
511+
if let Ok((_, loaded_range)) = &result
512+
&& loaded_range.end < missing_range.end
513+
{
514+
match row_count_opt {
515+
// Use pre-fetched value!
516+
Some(row_count) => {
517+
if loaded_range.end < row_count {
521518
set_known_row_count(loaded_range.end);
522519
}
523520
}
521+
None => {
522+
set_known_row_count(loaded_range.end);
523+
}
524524
}
525525
}
526526
loaded_rows.write().write_loaded(result, missing_range);

src/events.rs

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,30 @@ pub struct TableHeadEvent {
4848
pub mouse_event: MouseEvent,
4949
}
5050

51-
macro_rules! impl_default_arc_fn {
52-
(
53-
$(#[$meta:meta])*
54-
$name:ident<$($ty:ident),*>($($arg_name:ident: $arg_ty:ty),*)
55-
$(-> $ret_ty:ty)?
56-
$({ default $default_return:expr })?
57-
) => {
58-
$(#[$meta])*
59-
#[derive(Clone)]
60-
pub struct $name<$($ty),*>(Arc<dyn Fn($($arg_ty),*) $(-> $ret_ty)? + Send + Sync>);
51+
/// New type wrapper of a closure that takes a parameter `T`. This allows the event handler props
52+
/// to be optional while being able to take a simple closure.
53+
#[derive(Clone)]
54+
pub struct EventHandler<T>(Arc<dyn Fn(T) + Send + Sync>);
6155

62-
impl<$($ty),*> Default for $name<$($ty),*> {
63-
fn default() -> Self {
64-
#[allow(unused_variables)]
65-
Self(Arc::new(|$($arg_name: $arg_ty),*| {
66-
$($default_return)?
67-
}))
68-
}
69-
}
70-
71-
impl<F, $($ty),*> From<F> for $name<$($ty),*>
72-
where F: Fn($($arg_ty),*) $(-> $ret_ty)? + Send + Sync + 'static
73-
{
74-
fn from(f: F) -> Self { Self(Arc::new(f)) }
75-
}
76-
77-
impl<$($ty),*> $name<$($ty),*> {
78-
pub fn run(&self, $($arg_name: $arg_ty),*) $(-> $ret_ty)? {
79-
(self.0)($($arg_name),*)
80-
}
81-
}
56+
impl<T> Default for EventHandler<T> {
57+
fn default() -> Self {
58+
#[allow(unused_variables)]
59+
Self(Arc::new(|event: T| {}))
8260
}
8361
}
8462

85-
impl_default_arc_fn!(
86-
/// New type wrapper of a closure that takes a parameter `T`. This allows the event handler props
87-
/// to be optional while being able to take a simple closure.
88-
EventHandler<T>(event: T)
89-
);
63+
impl<F, T> From<F> for EventHandler<T>
64+
where
65+
F: Fn(T) + Send + Sync + 'static,
66+
{
67+
fn from(f: F) -> Self {
68+
Self(Arc::new(f))
69+
}
70+
}
9071

91-
pub(crate) use impl_default_arc_fn;
72+
impl<T> EventHandler<T> {
73+
#[inline]
74+
pub fn run(&self, event: T) {
75+
(self.0)(event)
76+
}
77+
}

0 commit comments

Comments
 (0)