diff --git a/src/batcher.rs b/src/batcher.rs index 22770f0..2195660 100644 --- a/src/batcher.rs +++ b/src/batcher.rs @@ -156,11 +156,11 @@ pub fn build_render_job( batches.push(batch); } - return RenderJob { + RenderJob { vertices, indices, batches, textures_delta, scale_factor, - }; + } } diff --git a/src/installer.rs b/src/installer.rs index 7285e78..94dde08 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -71,7 +71,7 @@ impl Installer { } } - pub fn frame(&mut self) -> anyhow::Result { + pub fn frame(&self) -> anyhow::Result { let draw_commands = self.draw_current_progress(); Ok(StageFrameOutput { @@ -107,7 +107,9 @@ impl Installer { pub fn handle_event(&mut self, event: StageEvent) -> anyhow::Result> { match event { StageEvent::Resized(size) => self.window_state.size = size, - StageEvent::ScaleFactorChanged(factor) => { + StageEvent::ScaleFactorChanged(factor) => + { + #[allow(clippy::cast_possible_truncation)] self.window_state.set_scale_factor(factor as f32) } _ => {} diff --git a/src/pob.rs b/src/pob.rs index 4689adb..d9a0d16 100644 --- a/src/pob.rs +++ b/src/pob.rs @@ -131,7 +131,7 @@ impl PathOfBuilding { Ok(lua) } - /// Adds "${script_dir}/lua" to package path + /// Adds `${script_dir}/lua` to package path pub fn register_package_paths(lua: &Lua, script_dir: &Path) -> LuaResult<()> { let package: Table = lua.globals().get("package")?; let mut package_path: String = package.get("path")?; @@ -155,7 +155,7 @@ impl PathOfBuilding { fn restart(&mut self) -> LuaResult<()> { // move context out of current lua instance... let mut ctx = self.lua.remove_app_data::().unwrap(); - let script_dir = ctx.script_dir.to_owned(); + let script_dir = ctx.script_dir.clone(); ctx.needs_restart = false; // and move it into new instance @@ -166,7 +166,7 @@ impl PathOfBuilding { } /// Handles events by updating context and forwarding them to PoB's event handlers. - pub fn handle_event(&mut self, event: StageEvent) -> anyhow::Result> { + pub fn handle_event(&self, event: StageEvent) -> anyhow::Result> { match event { StageEvent::KeyDown { key } => { self.ctx_mut().input_state.set_key_pressed(&key, true); @@ -238,6 +238,7 @@ impl PathOfBuilding { self.ctx_mut().window_state.size = size; } StageEvent::ScaleFactorChanged(scale_factor) => { + #[allow(clippy::cast_possible_truncation)] self.ctx_mut() .window_state .set_scale_factor(scale_factor as f32); @@ -358,7 +359,7 @@ impl PathOfBuilding { list_func.call::(()) } - pub fn clear_pressed(&mut self) { + pub fn clear_pressed(&self) { self.ctx_mut().input_state.clear_pressed(); } @@ -368,7 +369,7 @@ impl PathOfBuilding { } /// Attaches the render-target window to the context - pub fn set_window(&mut self, window: Arc) { + pub fn set_window(&self, window: Arc) { self.ctx_mut().window_state.set_window(window); } diff --git a/src/pob/api.rs b/src/pob/api.rs index 1a1ce9d..4882f2f 100644 --- a/src/pob/api.rs +++ b/src/pob/api.rs @@ -161,7 +161,7 @@ fn restart(l: &Lua, _: ()) -> LuaResult<()> { fn open_url(l: &Lua, url: String) -> LuaResult { match open::that(url) { - Ok(_) => ().into_lua_multi(l), + Ok(()) => ().into_lua_multi(l), Err(_) => "Unable to open url!".into_lua_multi(l), } } diff --git a/src/pob/api/lua.rs b/src/pob/api/lua.rs index 9a1c5cd..318b895 100644 --- a/src/pob/api/lua.rs +++ b/src/pob/api/lua.rs @@ -14,7 +14,7 @@ pub fn protected_call(l: &Lua, (func, args): (Function, MultiValue)) -> LuaResul pub fn load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult { let script_dir = { let ctx = l.app_data_ref::().unwrap(); - ctx.script_dir.to_owned() + ctx.script_dir.clone() }; let mut module_path = script_dir.join(name); if module_path.extension().is_none() { @@ -31,7 +31,7 @@ pub fn load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult LuaResult { let script_dir = { let ctx = l.app_data_ref::().unwrap(); - ctx.script_dir.to_owned() + ctx.script_dir.clone() }; let mut module_path = script_dir.join(name); if module_path.extension().is_none() { diff --git a/src/pob/api/paths.rs b/src/pob/api/paths.rs index 4a32385..f13ec15 100644 --- a/src/pob/api/paths.rs +++ b/src/pob/api/paths.rs @@ -42,7 +42,7 @@ pub fn set_work_dir(l: &Lua, path: String) -> LuaResult<()> { pub fn make_dir(l: &Lua, path: String) -> LuaResult { match fs::create_dir_all(path) { // callers expect first return value to be true on success - Ok(_) => (true).into_lua_multi(l), + Ok(()) => (true).into_lua_multi(l), // otherwise it is set to Nil and second return value is set to error msg Err(err) => (Value::Nil, err.to_string()).into_lua_multi(l), } @@ -55,7 +55,7 @@ pub fn remove_dir(l: &Lua, (path, recursive): (String, Option)) -> LuaResu fs::remove_dir(&path) }; match result { - Ok(_) => (true).into_lua_multi(l), + Ok(()) => (true).into_lua_multi(l), Err(err) => (Value::Nil, err.to_string()).into_lua_multi(l), } } diff --git a/src/pob/api/rendering.rs b/src/pob/api/rendering.rs index 4864dfc..6d4fc9b 100644 --- a/src/pob/api/rendering.rs +++ b/src/pob/api/rendering.rs @@ -168,7 +168,7 @@ unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int let layer = i32_from_stack!(state, -nargs); Some(layer) } - t => panic!("Expected Nil or Number, got {:?}", t), + t => panic!("Expected Nil or Number, got {t:?}"), }; let sublayer = i32_from_stack!(state, -nargs + 1); if let Some(layer) = layer { @@ -189,9 +189,10 @@ unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int { let mut ctx = lua_instance.app_data_mut::().unwrap(); let nargs = unsafe { ffi::lua_gettop(state) }; - if !matches!(nargs, 5 | 6 | 7 | 9 | 10 | 11) { - panic!("Unexpected number of arguments"); - } + assert!( + matches!(nargs, 5 | 6 | 7 | 9 | 10 | 11), + "Unexpected number of arguments" + ); #[allow(clippy::manual_range_patterns)] let parse_uv = matches!(nargs, 9 | 10 | 11); @@ -237,9 +238,10 @@ unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int let mut ctx = lua_instance.app_data_mut::().unwrap(); let nargs = unsafe { ffi::lua_gettop(state) }; - if !matches!(nargs, 9 | 10 | 11 | 17 | 18 | 19) { - panic!("Unexpected number of arguments"); - } + assert!( + matches!(nargs, 9 | 10 | 11 | 17 | 18 | 19), + "Unexpected number of arguments" + ); #[allow(clippy::manual_range_patterns)] let parse_uv = matches!(nargs, 17 | 18 | 19); @@ -560,17 +562,14 @@ impl<'a> Iterator for PoBStringSegmentIterator<'a> { let color = Some(Srgba::from_escape_code(escape_str)); let _ = self.captures.next(); // pop current code to peek the next one - match self.captures.peek() { - Some(next_code) => { - // found another escape code. return text up the next code - let next_code_start = next_code.get(0).unwrap().start(); - Some((color, &self.haystack[code_end..next_code_start])) - } - None => { - // no additional escape codes found. return rest of string - self.is_done = true; - Some((color, &self.haystack[code_end..])) - } + if let Some(next_code) = self.captures.peek() { + // found another escape code. return text up the next code + let next_code_start = next_code.get(0).unwrap().start(); + Some((color, &self.haystack[code_end..next_code_start])) + } else { + // no additional escape codes found. return rest of string + self.is_done = true; + Some((color, &self.haystack[code_end..])) } } None => { @@ -647,12 +646,12 @@ impl std::str::FromStr for PoBFontType { } } -#[inline(always)] +#[inline] fn hex_byte(a: u8, b: u8) -> u8 { (hex_digit(a) << 4) | hex_digit(b) } -#[inline(always)] +#[inline] fn hex_digit(c: u8) -> u8 { match c { b'0'..=b'9' => c - b'0', diff --git a/src/pob/api/subscript.rs b/src/pob/api/subscript.rs index ace768c..c68da42 100644 --- a/src/pob/api/subscript.rs +++ b/src/pob/api/subscript.rs @@ -21,7 +21,7 @@ pub fn launch_subscript( let arguments = args.try_into()?; let ctx = l.app_data_ref::().unwrap(); - let script_dir = ctx.script_dir.to_owned(); + let script_dir = ctx.script_dir.clone(); let subscript_id = ctx.subscript_manager.borrow_mut().push( script_dir, script_text, diff --git a/src/pob/subscript.rs b/src/pob/subscript.rs index 58e0a1f..68fcaaa 100644 --- a/src/pob/subscript.rs +++ b/src/pob/subscript.rs @@ -175,7 +175,7 @@ impl Subscript { } } - fn handle_calls(&mut self, lua: &Lua) { + fn handle_calls(&self, lua: &Lua) { match self.receiver.try_recv() { Ok(SubscriptCall::Blocking { function_name, diff --git a/src/renderer/image.rs b/src/renderer/image.rs index a0341bc..e200c3e 100644 --- a/src/renderer/image.rs +++ b/src/renderer/image.rs @@ -61,7 +61,7 @@ impl ImageData { height, array_layers: 1, mipmap_count: NonZeroU32::new(1).expect("1 is non-zero"), - data_order: Default::default(), + data_order: DataOrder::default(), bytes: RgbaImage::from_pixel(width, height, color.0.into()).into_raw(), } } @@ -75,7 +75,7 @@ impl From for ImageData { height: image.height(), array_layers: 1, mipmap_count: NonZeroU32::new(1).expect("1 is non-zero"), - data_order: Default::default(), + data_order: DataOrder::default(), bytes: image.to_rgba8().into_raw(), } } @@ -89,7 +89,7 @@ impl From for ImageData { height: image.height(), array_layers: 1, mipmap_count: NonZeroU32::new(1).expect("1 is non-zero"), - data_order: Default::default(), + data_order: DataOrder::default(), bytes: image.into_raw(), } } @@ -138,12 +138,10 @@ fn resolve_path>(path: P) -> std::path::PathBuf { /// Checks if file is a compressed DDS file (.dds.zst) fn is_compressed_dds>(path: P) -> bool { - let path = path.as_ref(); - path.extension().and_then(|s| s.to_str()) == Some("zst") - && path - .file_stem() - .and_then(|s| s.to_str()) - .is_some_and(|s| s.ends_with(".dds")) + path.as_ref() + .to_string_lossy() + .to_ascii_lowercase() + .ends_with(".dds.zst") } fn dds_format_to_wgpu(format: dds::Format) -> anyhow::Result { diff --git a/src/stage.rs b/src/stage.rs index b8fc6fd..e7b76a2 100644 --- a/src/stage.rs +++ b/src/stage.rs @@ -66,29 +66,29 @@ pub enum ActiveStage { impl ActiveStage { pub fn update(&mut self) -> anyhow::Result> { match self { - ActiveStage::Startup(s) => s.update(), - ActiveStage::Main(s) => s.update(), + Self::Startup(s) => s.update(), + Self::Main(s) => s.update(), } } pub fn frame(&mut self) -> anyhow::Result { match self { - ActiveStage::Startup(s) => s.frame(), - ActiveStage::Main(s) => s.frame(), + Self::Startup(s) => s.frame(), + Self::Main(s) => s.frame(), } } pub fn handle_event(&mut self, event: StageEvent) -> anyhow::Result> { match self { - ActiveStage::Startup(s) => s.handle_event(event), - ActiveStage::Main(s) => s.handle_event(event), + Self::Startup(s) => s.handle_event(event), + Self::Main(s) => s.handle_event(event), } } pub fn set_window(&mut self, window: Arc) { match self { - ActiveStage::Startup(s) => s.set_window(window), - ActiveStage::Main(s) => s.set_window(window), + Self::Startup(s) => s.set_window(window), + Self::Main(s) => s.set_window(window), } } diff --git a/src/window.rs b/src/window.rs index 89f129f..96aed9f 100644 --- a/src/window.rs +++ b/src/window.rs @@ -81,8 +81,6 @@ impl WindowState { } pub fn get_clipboard_text(&mut self) -> Option { - self.clipboard - .as_mut() - .and_then(|clipboard| clipboard.get_text()) + self.clipboard.as_mut().and_then(Clipboard::get_text) } }