From 023dd9dc000110a708b448872441fd37b42cffa3 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Wed, 6 Mar 2024 20:18:06 -0800 Subject: [PATCH] Clippy fixes --- examples/gltf-inspector.rs | 2 +- examples/shaders.rs | 14 ++------------ examples/toml-stuff.rs | 4 ++-- src/audio.rs | 2 +- src/debug.rs | 2 +- src/display3d.rs | 24 ++++++++++++------------ src/game.rs | 30 +++++++++++++++--------------- src/intro.rs | 3 +-- src/prelude.rs | 4 ++-- src/tweak.rs | 2 +- src/ui.rs | 8 ++++---- 11 files changed, 42 insertions(+), 53 deletions(-) diff --git a/examples/gltf-inspector.rs b/examples/gltf-inspector.rs index b5c480e..63b42a7 100644 --- a/examples/gltf-inspector.rs +++ b/examples/gltf-inspector.rs @@ -25,7 +25,7 @@ fn inspect( // Spawn default GLTF scene commands.spawn(( SceneBundle { - scene: Handle::Weak(id.clone()), + scene: Handle::Weak(*id), ..default() }, InspectScene, diff --git a/examples/shaders.rs b/examples/shaders.rs index c350155..d116bef 100644 --- a/examples/shaders.rs +++ b/examples/shaders.rs @@ -1,14 +1,4 @@ -use bevy::core_pipeline::experimental::taa::TemporalAntiAliasSettings; -use bevy::core_pipeline::prepass::MotionVectorPrepass; -use bevy::core_pipeline::tonemapping::DebandDither; -use bevy::core_pipeline::Skybox; -use bevy::pbr::ExtendedMaterial; -use bevy::pbr::MaterialExtension; -use bevy::pbr::OpaqueRendererMethod; -use bevy::pbr::ScreenSpaceAmbientOcclusionBundle; -use bevy::prelude::*; -use bevy::render::render_resource::*; -use bevy::render::view::ColorGrading; +use crate::prelude::*; type MyMat = ExtendedMaterial; @@ -82,7 +72,7 @@ fn apply_skybox( }); cameras.iter().for_each(|e| { - commands.entity(e).insert(Skybox(handle.clone())); + commands.entity(e).insert(Skybox { image: handle.clone(), brightness: 1.0 }); }); *done = true; diff --git a/examples/toml-stuff.rs b/examples/toml-stuff.rs index 8a4353a..8d19fff 100644 --- a/examples/toml-stuff.rs +++ b/examples/toml-stuff.rs @@ -39,7 +39,7 @@ fn main() { fn iter_all(t: &toml::Table, key: &str) -> Vec<(String, toml::Value)> { t.iter() .flat_map(|(k, v)| { - let nk = if key == "" { + let nk = if key.is_empty() { k.to_string() } else { format!("{}_{}", key, k) @@ -69,5 +69,5 @@ fn locate(t: &toml::Table, key: &str) -> Option { } fn get<'de, T: Deserialize<'de>>(t: &toml::Table, key: &str) -> Option { - locate(t, key).map(|val| val.try_into().ok()).flatten() + locate(t, key).and_then(|val| val.try_into().ok()) } diff --git a/src/audio.rs b/src/audio.rs index e8680eb..2ff97cc 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -145,5 +145,5 @@ fn toggle_volume(mut vol: ResMut) { fn control_volume(vol: Res, query: Query<&AudioSource>) { query .iter() - .for_each(|aud_src| aud_src.set_volume((*vol).0)); + .for_each(|aud_src| aud_src.set_volume(vol.0)); } diff --git a/src/debug.rs b/src/debug.rs index 14e8120..2011045 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -6,7 +6,7 @@ impl Plugin for DebugPlugin { fn build(&self, app: &mut App) { app.add_plugins(( FrameTimeDiagnosticsPlugin, - EntityCountDiagnosticsPlugin::default(), + EntityCountDiagnosticsPlugin, SystemInformationDiagnosticsPlugin, )) .init_resource::() diff --git a/src/display3d.rs b/src/display3d.rs index 03e13dc..b5c4414 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -203,8 +203,8 @@ fn initialize(mut commands: Commands, board: Res, assets: Res Option { match self { - Self::FadeOut(e) => Some(Self::Store(e.clone())), - Self::Store(e) => Some(Self::FadeIn(e.clone())), + Self::FadeOut(e) => Some(Self::Store(*e)), + Self::Store(e) => Some(Self::FadeIn(*e)), Self::FadeIn(_) => None, } } @@ -297,7 +297,7 @@ impl Board { .map(|p| (p, BoardIndex { x, y })) }) }) - .filter_map(|r| r) + .flatten() .collect() } Side::B => { @@ -309,7 +309,7 @@ impl Board { .map(|p| (p, BoardIndex { x, y })) }) }) - .filter_map(|r| r) + .flatten() .collect() } } @@ -322,7 +322,7 @@ impl Board { .enumerate() .flat_map(|(y, nested)| { nested.iter().enumerate().filter_map(move |(x, p)| { - p.as_ref().map(|val| (BoardIndex { x, y }, val.clone())) + p.as_ref().map(|val| (BoardIndex { x, y }, *val)) }) }) .collect() @@ -337,7 +337,7 @@ impl Board { if from == to { Err(GameError::NullMove) } else { - match self.at(from.clone()) { + match self.at(from) { Some(from_piece) => { // Check if this is a valid move for this piece if self.valid_moves(from).contains(&to) { @@ -351,7 +351,7 @@ impl Board { if self.inner[to.y][to.x].is_some() { moves.push(Move { epoch, - from: to.clone(), + from: to, to: None, }); } @@ -359,8 +359,8 @@ impl Board { // Capture the intened move in the moves ledger moves.push(Move { epoch, - from: from.clone(), - to: Some(to.clone()), + from: from, + to: Some(to), }); self.inner[to.y][to.x] = Some(*from_piece); @@ -500,7 +500,7 @@ impl Board { impl std::fmt::Display for Board { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.inner.iter().rev().for_each(|row| { - let _ = write!(f, "+--+--+--+--+--+--+--+--+\n"); + let _ = writeln!(f, "+--+--+--+--+--+--+--+--+"); let _ = write!(f, "|"); row.iter().for_each(|piece| { let _ = match piece { @@ -508,7 +508,7 @@ impl std::fmt::Display for Board { None => write!(f, " |"), }; }); - let _ = write!(f, "\n"); + let _ = writeln!(f); }); let _ = write!(f, "+--+--+--+--+--+--+--+--+"); Ok(()) @@ -552,7 +552,7 @@ pub(crate) fn update_board( match to { Some(to_idx) => { info!("Moving piece {:?} {:?} -> {:?}", entity, from, to_idx); - *index = to_idx.clone(); + *index = *to_idx; if !(*played) { audio_events.send(audio::AudioEvent::PutDown); audio_events.send(audio::AudioEvent::StopIdle); @@ -853,8 +853,8 @@ fn cancel_place(current: Query<&BoardIndex, With>, mut events: EventWr current.iter().for_each(|board_index| { info!("De-selecting piece at {:?}", board_index); events.send(Move { - from: board_index.clone(), - to: Some(board_index.clone()), + from: *board_index, + to: Some(*board_index), ..default() }); }); @@ -938,7 +938,7 @@ fn reset_game( .for_each(|(e, (i, p))| { commands .entity(e) - .insert((i.clone(), p.clone())) + .insert((*i, *p)) .remove::(); }); } diff --git a/src/intro.rs b/src/intro.rs index 4f91fdd..7e81f9c 100644 --- a/src/intro.rs +++ b/src/intro.rs @@ -96,7 +96,6 @@ fn init_intro_text( text: Text { sections: text .chars() - .into_iter() .map(|c| TextSection { value: c.to_string(), style: TextStyle { @@ -208,7 +207,7 @@ fn manage_scroll_text_animation( commands.entity(e).insert(Visibility::Hidden); } // Locate the last entity we were operating with - while let Some(entity) = paragraphs.next() { + for entity in paragraphs.by_ref() { if curr.0 == Some(entity) { break; } diff --git a/src/prelude.rs b/src/prelude.rs index 398d078..5cfce7c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -21,8 +21,8 @@ pub(crate) use bevy::{ mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel}, ButtonState, }, - pbr::ScreenSpaceAmbientOcclusionQualityLevel, pbr::{ + ScreenSpaceAmbientOcclusionQualityLevel, OpaqueRendererMethod, ExtendedMaterial, MaterialExtension, ScreenSpaceAmbientOcclusionBundle, ScreenSpaceAmbientOcclusionSettings, }, @@ -31,7 +31,7 @@ pub(crate) use bevy::{ render::{ mesh::{MeshVertexAttribute, VertexAttributeValues}, render_resource::{ - AsBindGroup, ShaderRef, TextureViewDescriptor, TextureViewDimension, VertexFormat, + *, AsBindGroup, ShaderRef, TextureViewDescriptor, TextureViewDimension, VertexFormat, }, view::ColorGrading, }, diff --git a/src/tweak.rs b/src/tweak.rs index 509adfb..738cd62 100644 --- a/src/tweak.rs +++ b/src/tweak.rs @@ -79,7 +79,7 @@ impl Tweaks { fn iter_all(t: &toml::Table, key: &str) -> Vec<(String, toml::Value)> { t.iter() .flat_map(|(k, v)| { - let nk = if key == "" { + let nk = if key.is_empty() { k.to_string() } else { format!("{}_{}", key, k) diff --git a/src/ui.rs b/src/ui.rs index f8d571c..17802bb 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -66,7 +66,7 @@ fn manage_cursor( fn interactive_button( mut events: Query<(Entity, &mut UiImage, &Interaction), (With