From 9becbe3c4dd1a6632a07b471070e1ddd9891df3b Mon Sep 17 00:00:00 2001 From: PenguinWithATie <166940857+PenguinWithATie@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:31:13 -0600 Subject: [PATCH] fix clippy warnings (#415) --- .../molecules/analysis_and_download.rs | 2 +- .../components/molecules/control_buttons.rs | 2 +- apis/src/components/molecules/live_timer.rs | 2 +- apis/src/components/molecules/my_schedules.rs | 2 +- apis/src/components/molecules/rl_banner.rs | 6 ++-- .../components/molecules/user_with_rating.rs | 2 +- .../components/organisms/analysis/atoms.rs | 6 ++-- .../components/organisms/analysis/history.rs | 2 +- .../src/components/organisms/display_timer.rs | 2 +- apis/src/components/organisms/reserve.rs | 4 +-- apis/src/pages/play.rs | 2 +- apis/src/pages/tournament_create.rs | 30 +++++++++---------- apis/src/providers/chat.rs | 4 +-- apis/src/providers/config.rs | 2 +- .../websocket/server_handlers/games_search.rs | 2 +- db/src/models/game.rs | 4 +-- engine/src/hasher.rs | 2 +- 17 files changed, 37 insertions(+), 39 deletions(-) diff --git a/apis/src/components/molecules/analysis_and_download.rs b/apis/src/components/molecules/analysis_and_download.rs index acf59f7c..c2ed2735 100644 --- a/apis/src/components/molecules/analysis_and_download.rs +++ b/apis/src/components/molecules/analysis_and_download.rs @@ -12,7 +12,7 @@ pub fn AnalysisAndDownload() -> impl IntoView { game_state.do_analysis(); }; let correspondence = create_read_slice(game_state.signal, |gs| { - gs.game_response.as_ref().map_or(false, |gr| { + gs.game_response.as_ref().is_some_and(|gr| { gr.speed == GameSpeed::Correspondence || gr.speed == GameSpeed::Untimed }) }); diff --git a/apis/src/components/molecules/control_buttons.rs b/apis/src/components/molecules/control_buttons.rs index 1b63e2d9..8c8a0690 100644 --- a/apis/src/components/molecules/control_buttons.rs +++ b/apis/src/components/molecules/control_buttons.rs @@ -31,7 +31,7 @@ pub fn ControlButtons() -> impl IntoView { let not_tournament = create_read_slice(game_state.signal, |gs| { gs.game_response .as_ref() - .map_or(false, |gr| gr.tournament.is_none()) + .is_some_and(|gr| gr.tournament.is_none()) }); let takeback_allowed = create_read_slice(game_state.signal, |gs| gs.takeback_allowed()); let navigate_to_tournament = move |_| { diff --git a/apis/src/components/molecules/live_timer.rs b/apis/src/components/molecules/live_timer.rs index 85b23bbb..f99fea14 100644 --- a/apis/src/components/molecules/live_timer.rs +++ b/apis/src/components/molecules/live_timer.rs @@ -31,7 +31,7 @@ pub fn LiveTimer(side: Signal) -> impl IntoView { let in_progress = create_read_slice(game_state.signal, |gs| { gs.game_response .as_ref() - .map_or(false, |gr| gr.game_status == GameStatus::InProgress) + .is_some_and(|gr| gr.game_status == GameStatus::InProgress) }); let timer = expect_context::().signal; let tick_rate = Duration::from_millis(100); diff --git a/apis/src/components/molecules/my_schedules.rs b/apis/src/components/molecules/my_schedules.rs index f0d1fab0..c393c5c8 100644 --- a/apis/src/components/molecules/my_schedules.rs +++ b/apis/src/components/molecules/my_schedules.rs @@ -22,7 +22,7 @@ pub fn MySchedules( user_id: Signal>, ) -> impl IntoView { let has_schedules = move || { - user_id().map_or(false, |user_id| { + user_id().is_some_and(|user_id| { games_hashmap.get().iter().any(|(_game_id, game)| { game.game_status == GameStatus::NotStarted && (game.white_player.uid == user_id || game.black_player.uid == user_id) diff --git a/apis/src/components/molecules/rl_banner.rs b/apis/src/components/molecules/rl_banner.rs index 8347b2ce..bbdd793b 100644 --- a/apis/src/components/molecules/rl_banner.rs +++ b/apis/src/components/molecules/rl_banner.rs @@ -4,11 +4,9 @@ use leptos::*; pub fn RlBanner() -> impl IntoView { view! {
-

- King of the Hive -

+

King of the Hive

- 2025 February Season starts soon! Find out more + 2025 February Season starts soon! Find out more { view! { } diff --git a/apis/src/components/organisms/analysis/atoms.rs b/apis/src/components/organisms/analysis/atoms.rs index 906295de..41be481c 100644 --- a/apis/src/components/organisms/analysis/atoms.rs +++ b/apis/src/components/organisms/analysis/atoms.rs @@ -14,7 +14,7 @@ pub fn UndoButton() -> impl IntoView { let is_disabled = move || { analysis .get() - .map_or(true, |analysis| analysis.current_node.is_none()) + .is_none_or(|analysis| analysis.current_node.is_none()) }; let undo = move |_| { analysis.update(|a| { @@ -75,8 +75,8 @@ pub fn HistoryButton( }; let is_disabled = move || { - analysis.get().map_or(true, |analysis| { - analysis.current_node.map_or(true, |n| match cloned_action { + analysis.get().is_none_or(|analysis| { + analysis.current_node.is_none_or(|n| match cloned_action { HistoryNavigation::Next => n.get_children_ids().is_empty(), HistoryNavigation::Previous => n.get_parent_id().is_none(), }) diff --git a/apis/src/components/organisms/analysis/history.rs b/apis/src/components/organisms/analysis/history.rs index f8369f3d..5e3678ed 100644 --- a/apis/src/components/organisms/analysis/history.rs +++ b/apis/src/components/organisms/analysis/history.rs @@ -78,7 +78,7 @@ pub fn History(#[prop(optional)] mobile: bool) -> impl IntoView { let children_ids = node.get_children_ids(); let siblings_ids = tree.get_sibling_ids(&node_id, true).ok()?; let parent_deg = siblings_ids.len(); - let not_first_sibling = siblings_ids.first().map_or(true, |s| *s != node_id); + let not_first_sibling = siblings_ids.first().is_none_or(|s| *s != node_id); content = if children_ids.len() > 1 { /* == More than one child == gather all children but the first (secondary variations) diff --git a/apis/src/components/organisms/display_timer.rs b/apis/src/components/organisms/display_timer.rs index 78e9e0db..c3239a38 100644 --- a/apis/src/components/organisms/display_timer.rs +++ b/apis/src/components/organisms/display_timer.rs @@ -26,7 +26,7 @@ pub fn DisplayTimer(placement: Placement, vertical: bool) -> impl IntoView { }; let black_id = create_read_slice(game_state.signal, |gs| gs.black_id); let player_is_black = - create_memo(move |_| user().map_or(false, |user| Some(user.id) == black_id())); + create_memo(move |_| user().is_some_and(|user| Some(user.id) == black_id())); let side = Signal::derive(move || match (player_is_black(), placement) { (true, Placement::Top) => Color::White, (true, Placement::Bottom) => Color::Black, diff --git a/apis/src/components/organisms/reserve.rs b/apis/src/components/organisms/reserve.rs index 53dc7284..24fceac5 100644 --- a/apis/src/components/organisms/reserve.rs +++ b/apis/src/components/organisms/reserve.rs @@ -87,7 +87,7 @@ pub fn Reserve( let tournament = game_state .game_response .as_ref() - .map_or(false, |gr| gr.tournament.is_some()); + .is_some_and(|gr| gr.tournament.is_some()); let status = game_state .game_response .as_ref() @@ -197,7 +197,7 @@ pub fn ReserveContent(player_color: Memo) -> impl IntoView { }; let white_and_black = create_read_slice(game_state.signal, |gs| (gs.white_id, gs.black_id)); let show_buttons = move || { - user().map_or(false, |user| { + user().is_some_and(|user| { let (white_id, black_id) = white_and_black(); Some(user.id) == black_id || Some(user.id) == white_id }) diff --git a/apis/src/pages/play.rs b/apis/src/pages/play.rs index de17b536..61fbca7d 100644 --- a/apis/src/pages/play.rs +++ b/apis/src/pages/play.rs @@ -92,7 +92,7 @@ pub fn Play(#[prop(optional)] extend_tw_classes: &'static str) -> impl IntoView let show_controls = Signal::derive(move || !controls_signal.hidden.get() || game_state.is_finished()()); let show_board = create_read_slice(game_state.signal, |gs| { - !gs.game_response.as_ref().map_or(false, |gr| { + !gs.game_response.as_ref().is_some_and(|gr| { gr.game_start == GameStart::Ready && matches!(gr.game_status, GameStatus::NotStarted) && gr.tournament_game_result == TournamentGameResult::Unknown diff --git a/apis/src/pages/tournament_create.rs b/apis/src/pages/tournament_create.rs index 7e0890ff..c45fdbfe 100644 --- a/apis/src/pages/tournament_create.rs +++ b/apis/src/pages/tournament_create.rs @@ -276,22 +276,22 @@ pub fn TournamentCreate() -> impl IntoView { attr:maxlength="2000" > -

diff --git a/apis/src/providers/chat.rs b/apis/src/providers/chat.rs index a0835a51..b1e3a8c8 100644 --- a/apis/src/providers/chat.rs +++ b/apis/src/providers/chat.rs @@ -48,12 +48,12 @@ impl Chat { self.games_public_new_messages .get() .get(&game_id) - .map_or(false, |v| *v) + .is_some_and(|v| *v) || self .games_private_new_messages .get() .get(&game_id) - .map_or(false, |v| *v) + .is_some_and(|v| *v) } else { false } diff --git a/apis/src/providers/config.rs b/apis/src/providers/config.rs index 64553839..a21dab87 100644 --- a/apis/src/providers/config.rs +++ b/apis/src/providers/config.rs @@ -55,7 +55,7 @@ impl ConfigOpts { let prefers_sound = prefers_sound().unwrap_or_default(); let (prefers_dark, _) = use_cookie::("darkmode"); - let prefers_dark = prefers_dark().map_or(false, |v| v == "true"); + let prefers_dark = prefers_dark().is_some_and(|v| v == "true"); let mut confirm_mode = HashMap::new(); for speed in GameSpeed::all().iter() { diff --git a/apis/src/websocket/server_handlers/games_search.rs b/apis/src/websocket/server_handlers/games_search.rs index 86397b0a..05c4dadb 100644 --- a/apis/src/websocket/server_handlers/games_search.rs +++ b/apis/src/websocket/server_handlers/games_search.rs @@ -40,7 +40,7 @@ impl GamesSearchHandler { results: game_responses, batch, ctx_to_update: self.options.ctx_to_update.clone(), - more_rows: options.batch_size.map_or(false, |b| b == games.len()), + more_rows: options.batch_size == Some(games.len()), first_batch: options.current_batch.is_none(), }; Ok(vec![InternalServerMessage { diff --git a/db/src/models/game.rs b/db/src/models/game.rs index 36dc4a2a..d0626ed3 100644 --- a/db/src/models/game.rs +++ b/db/src/models/game.rs @@ -714,8 +714,8 @@ impl Game { } pub fn last_game_control(&self) -> Option { - if let Some(last) = self.game_control_history.split_terminator(';').last() { - if let Some(gc) = last.split(' ').last() { + if let Some(last) = self.game_control_history.split_terminator(';').next_back() { + if let Some(gc) = last.split(' ').next_back() { return Some( GameControl::from_str(gc) .expect("Could not get GameControl from game_control_history"), diff --git a/engine/src/hasher.rs b/engine/src/hasher.rs index 00ca2a40..4da04786 100644 --- a/engine/src/hasher.rs +++ b/engine/src/hasher.rs @@ -41,7 +41,7 @@ impl Hasher { } else { panic!("We need an index"); }; - self.hashes[revolution as usize] ^= Self::hash(index << 32 | bug_stack.simple() as u64); + self.hashes[revolution as usize] ^= Self::hash((index << 32) | bug_stack.simple() as u64); } // This implements wyhash