diff --git a/src/api.rs b/src/api.rs index 489e7b1..9a8d875 100644 --- a/src/api.rs +++ b/src/api.rs @@ -79,7 +79,7 @@ pub fn register_globals(lua: &Lua) -> LuaResult<()> { globals.set("NewFileSearch", lua.create_function(new_search_handle)?)?; // image handle - register_image_handle_api(&lua)?; + register_image_handle_api(lua)?; // clipboard globals.set("Copy", lua.create_function(copy)?)?; diff --git a/src/api/callback.rs b/src/api/callback.rs index 92d6d48..30f8efc 100644 --- a/src/api/callback.rs +++ b/src/api/callback.rs @@ -12,16 +12,15 @@ pub fn get_callback(lua: &Lua, name: &str) -> LuaResult { if callback_function.is_function() { // function defined through `SetCallback` return Ok(callback_function.as_function().unwrap().clone()); - } else { - // look for function in `MainObject` - let main_object: Table = callback_table.get("MainObject")?; - let callback_function: Value = main_object.get(name)?; - if callback_function.is_function() { - // these functions expect `MainObject` as first argument so we bind it here - return callback_function.as_function().unwrap().bind(main_object); - } } - Err(anyhow::anyhow!("Function '{}' not found", name).into()) + // look for function in `MainObject` + let main_object: Table = callback_table.get("MainObject")?; + let callback_function: Value = main_object.get(name)?; + if callback_function.is_function() { + // these functions expect `MainObject` as first argument so we bind it here + return callback_function.as_function().unwrap().bind(main_object); + } + Err(anyhow::anyhow!("Function '{name}' not found").into()) } pub fn set_main_object(l: &Lua, main_object: Table) -> LuaResult<()> { diff --git a/src/api/console.rs b/src/api/console.rs index 9d714ed..8b05642 100644 --- a/src/api/console.rs +++ b/src/api/console.rs @@ -34,9 +34,9 @@ fn print_table(table: &Table, indent: usize, recursive: bool) -> LuaResult<()> { let (key, value) = pair?; if key.is_string() { - write!(lock, "{0:>1$}\"{2}\" = ", "", inner_ind, key.to_string()?,)?; + write!(lock, "{0:>1$}\"{2}\" = ", "", inner_ind, key.to_string()?)?; } else { - write!(lock, "{0:>1$}{2} = ", "", inner_ind, key.to_string()?,)?; + write!(lock, "{0:>1$}{2} = ", "", inner_ind, key.to_string()?)?; } if value.is_table() { diff --git a/src/api/image_handle.rs b/src/api/image_handle.rs index b4cdafa..457eb5f 100644 --- a/src/api/image_handle.rs +++ b/src/api/image_handle.rs @@ -74,7 +74,7 @@ unsafe fn push_image_handle(state: *mut ffi::lua_State) -> *mut ImageHandle { ptr } -/// Puts ImageHandle on the Lua stack +/// Puts `ImageHandle` on the Lua stack unsafe extern "C-unwind" fn new_image_handle(state: *mut ffi::lua_State) -> c_int { unsafe { push_image_handle(state); @@ -87,7 +87,7 @@ unsafe extern "C-unwind" fn new_image_handle(state: *mut ffi::lua_State) -> c_in 1 } -/// Get an ImageHandle from the Lua stack. +/// Gets an `ImageHandle` from the Lua stack. #[inline] unsafe fn get_image_handle(state: *mut ffi::lua_State, index: c_int) -> *mut ImageHandle { unsafe { @@ -114,7 +114,7 @@ pub unsafe fn image_handle_texture_id( unsafe { (*ptr).texture_id() } } -// Drops the ImageHandle +// Drops the `ImageHandle` unsafe extern "C-unwind" fn image_handle_gc(state: *mut ffi::lua_State) -> c_int { let ptr = unsafe { ffi::lua_touserdata(state, 1) } as *mut ImageHandle; diff --git a/src/api/paths.rs b/src/api/paths.rs index f39bd49..434790c 100644 --- a/src/api/paths.rs +++ b/src/api/paths.rs @@ -27,7 +27,7 @@ pub fn get_runtime_path(_: &Lua, _: ()) -> LuaResult { pub fn get_work_dir(l: &Lua, _: ()) -> LuaResult { let ctx = l.app_data_ref::<&'static Context>().unwrap(); - Ok(ctx.current_working_dir().to_path_buf()) + Ok(ctx.current_working_dir().clone()) } // NOTE: unused diff --git a/src/api/rendering.rs b/src/api/rendering.rs index 5f77a99..78cd121 100644 --- a/src/api/rendering.rs +++ b/src/api/rendering.rs @@ -108,7 +108,7 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int ctx.layers().set_draw_color(color); } _ => panic!("Unexpected number of arguments"), - }; + } 0 } @@ -146,7 +146,7 @@ unsafe extern "C-unwind" fn set_viewport(state: *mut ffi::lua_State) -> c_int { ctx.layers().set_viewport(rect); } _ => panic!("Unexpected number of arguments"), - }; + } 0 } @@ -180,7 +180,7 @@ unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int } } _ => panic!("Unexpected number of arguments"), - }; + } 0 } @@ -313,13 +313,11 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int { let font_type = str_from_stack!(state, -nargs + 4); let text = str_from_stack!(state, -nargs + 5); - let alignment = match alignment.parse::() { - Ok(alignment) => alignment, - Err(_) => panic!("Invalid alignment"), + let Ok(alignment) = alignment.parse::() else { + panic!("Invalid alignment"); }; - let font_type = match font_type.parse::() { - Ok(font_type) => font_type, - Err(_) => panic!("Invalid font type"), + let Ok(font_type) = font_type.parse::() else { + panic!("Invalid font type"); }; let mut position = Point::new(x, y); @@ -375,9 +373,8 @@ unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) -> c_in let font_type = str_from_stack!(state, -nargs + 1); let text = str_from_stack!(state, -nargs + 2); - let font_type = match font_type.parse::() { - Ok(font_type) => font_type, - Err(_) => panic!("Invalid font type"), + let Ok(font_type) = font_type.parse::() else { + panic!("Invalid font type"); }; let job = build_layout_job(text, Srgba::WHITE, font_type, line_height, None); @@ -478,7 +475,7 @@ fn build_layout_job<'a>( font_style, ); - for (color, segment) in PoBString(text).into_iter() { + for (color, segment) in PoBString(text) { job.append(segment, color.unwrap_or(current_color)); } @@ -600,10 +597,7 @@ impl std::str::FromStr for PoBTextAlignment { "RIGHT" => Ok(Self::Right), "CENTER_X" => Ok(Self::CenterX), "RIGHT_X" => Ok(Self::RightX), - _ => Err(anyhow::anyhow!( - "'{}' is not a valid TextFontType variant", - s - )), + _ => Err(anyhow::anyhow!("'{s}' is not a valid TextFontType variant")), } } } @@ -631,10 +625,7 @@ impl std::str::FromStr for PoBFontType { "FONTIN SC ITALIC" => Ok(Self::FontinSmallcapsItalic), "FONTIN" => Ok(Self::Fontin), "FONTIN ITALIC" => Ok(Self::FontinItalic), - _ => Err(anyhow::anyhow!( - "'{}' is not a valid TextFontType variant", - s - )), + _ => Err(anyhow::anyhow!("'{s}' is not a valid TextFontType variant")), } } } diff --git a/src/api/search_handle.rs b/src/api/search_handle.rs index b60695e..1adb8be 100644 --- a/src/api/search_handle.rs +++ b/src/api/search_handle.rs @@ -19,7 +19,7 @@ pub fn new_search_handle( if handle.current.is_some() { return handle.into_lua(l); } - }; + } Ok(Value::Nil) } diff --git a/src/fonts/layout.rs b/src/fonts/layout.rs index 669be8c..c08d565 100644 --- a/src/fonts/layout.rs +++ b/src/fonts/layout.rs @@ -72,15 +72,12 @@ impl std::hash::Hash for LayoutJob<'_> { fn hash(&self, state: &mut H) { self.segments.hash(state); match &self.font_family { - FontFamily::Single(FontFamilyName::Named(cow)) => { + FontFamily::Single(FontFamilyName::Named(cow)) | FontFamily::Source(cow) => { cow.hash(state); } FontFamily::Single(FontFamilyName::Generic(generic_family)) => { generic_family.hash(state); } - FontFamily::Source(cow) => { - cow.hash(state); - } FontFamily::List(cow) => { for name in cow.iter() { match name { diff --git a/src/fonts/rasterizer.rs b/src/fonts/rasterizer.rs index a933c69..48452a6 100644 --- a/src/fonts/rasterizer.rs +++ b/src/fonts/rasterizer.rs @@ -118,7 +118,7 @@ impl GlyphRasterizer { self.cached_glyphs.clear(); } - /// Gets a swash::FontRef from FontData + /// Gets a [`swash::FontRef`] from [`FontData`] fn get_font_ref<'a>(&mut self, font: &'a FontData) -> swash::FontRef<'a> { let font_blob_id = font.data.id(); diff --git a/src/input.rs b/src/input.rs index 8da0321..d015fa1 100644 --- a/src/input.rs +++ b/src/input.rs @@ -22,11 +22,11 @@ struct MousePressState { pub struct InputState { /// Current state(s) of modifier keys. (Shift, Control, Alt, Super) pub key_modifiers: ModifiersState, - /// HashSet of currently pressed keyboard keys. + /// `HashSet` of currently pressed keyboard keys. keys_pressed: HashSet, - /// HashSet of currently pressed mouse buttons. + /// `HashSet` of currently pressed mouse buttons. mouse_pressed: HashSet, - /// HashMap of mouse buttons (keys) with the last time they were pressed. + /// `HashMap` of mouse buttons (keys) with the last time they were pressed. mouse_last_pressed: HashMap, /// Current cursor position relative to the top-left corner of the window. cursor_pos: LogicalPoint, @@ -105,7 +105,7 @@ impl InputState { } } -/// Attempts to convert the provided string `s` to a [winit::keyboard::Key]. +/// Attempts to convert the provided string `s` to a [`winit::keyboard::Key`]. /// Returns [None] if no matching Key found. pub fn str_as_key(s: &str) -> Option { Some(match s.to_uppercase().as_str() { @@ -188,7 +188,7 @@ pub fn str_as_key(s: &str) -> Option { }) } -/// Attempts to convert the provided [winit::keyboard::Key] `key` to a string +/// Attempts to convert the provided [`winit::keyboard::Key`] `key` to a string /// representation that PoB recognizes. /// /// Returns [None] if no matching string found. @@ -257,10 +257,10 @@ pub fn str_as_mousebutton(s: &str) -> Option { }) } -/// Attempts to convert the provided [MouseButton] to a [SmolStr] that the PoB Lua +/// Attempts to convert the provided [`MouseButton`] to a [`SmolStr`] that the PoB Lua /// backend recognizes. /// -/// Returns [None] if no matching [MouseButton] was found. +/// Returns [None] if no matching [`MouseButton`] was found. pub fn mousebutton_as_str(button: MouseButton) -> Option { Some(match button { MouseButton::Left => SmolStr::new("LEFTBUTTON"), diff --git a/src/installer.rs b/src/installer.rs index 8268605..1a4246f 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -220,7 +220,7 @@ fn fetch_compatibility_info( // Beta versions have a non-semver suffix and are filtered out by the regex. Ok(compatibility_table .pairs::() - .filter_map(|p| p.ok()) + .filter_map(Result::ok) .filter(|(pob_version, _)| VERSION_RE.is_match(pob_version)) .map(|(pob_version, min_req_rpob_ver)| VersionReq { pob_ver: pob_version, @@ -292,7 +292,7 @@ fn download_pob>( ]; download_and_extract_tarball( - &client, + client, pob_repo, &format!("v{pob_version}"), &rules, @@ -313,7 +313,7 @@ fn download_pob>( format!("Downloading assets... ({})", format_bytes(downloaded)) } DownloadEvent::Retrying { attempt } => { - format!("Retrying... (Attempt {})", attempt) + format!("Retrying... (Attempt {attempt})") } }; let _ = progress_tx.send(Progress::Status(msg)); @@ -391,7 +391,7 @@ fn is_higher_version(v1: &str, v2: &str) -> anyhow::Result { let parse_version = |v: &str| -> anyhow::Result<(u32, u32, u32)> { let caps = VERSION_RE .captures(v) - .ok_or_else(|| anyhow::anyhow!("Invalid semver format: {}", v))?; + .ok_or_else(|| anyhow::anyhow!("Invalid semver format: {v}"))?; let major = caps[1].parse::().unwrap(); let minor = caps[2].parse::().unwrap(); diff --git a/src/installer/download.rs b/src/installer/download.rs index 586f3ea..5ec5ab5 100644 --- a/src/installer/download.rs +++ b/src/installer/download.rs @@ -19,7 +19,7 @@ pub enum DownloadEvent { /// Build a reqwest blocking client pub fn build_client() -> Result { - Client::builder().timeout(Duration::from_secs(60)).build() + Client::builder().timeout(Duration::from_mins(1)).build() } // Rate-limit-aware GET. @@ -194,9 +194,8 @@ pub fn download_and_extract_tarball( } // Strip root folder before matching against rules - let relative = match entry_str.split_once('/') { - Some((_, rest)) => rest, - None => continue, + let Some((_, relative)) = entry_str.split_once('/') else { + continue; }; let dest: Option = rules.iter().find_map(|rule| match rule { diff --git a/src/layers.rs b/src/layers.rs index 3a3f871..8ded933 100644 --- a/src/layers.rs +++ b/src/layers.rs @@ -123,7 +123,7 @@ impl Layers { pub fn add_text(&mut self, mut text: TextPrimitive, is_absolute_position: bool) { if !is_absolute_position { text.translate(self.viewport.min.to_vector()); - }; + } let clipped_primitive = ClippedPrimitive { clip_rect: self.viewport, diff --git a/src/lua.rs b/src/lua.rs index a61d324..8db5ae9 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -15,7 +15,7 @@ use clap::Parser; use mlua::{Function, Lua, Result as LuaResult, Table, thread::ThreadStatus}; use std::{ cell::{Cell, RefCell}, - path::PathBuf, + path::{Path, PathBuf}, rc::Rc, }; use winit::keyboard::SmolStr; @@ -77,7 +77,7 @@ impl Context { self.input.set(&ctx.app.input); self.fonts.set(&mut ctx.app.fonts); self.texture_manager.set(&mut ctx.app.texture_manager); - self.script_dir.set(&mut ctx.app.script_dir); + self.script_dir.set(&ctx.app.script_dir); self.current_working_dir .set(&mut ctx.pob.current_working_dir); self.layers.set(&mut ctx.pob.layers); @@ -131,14 +131,14 @@ pub enum PoBEvent { impl std::fmt::Display for PoBEvent { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - PoBEvent::Init => write!(f, "Init"), - PoBEvent::Exit => write!(f, "Exit"), - PoBEvent::Frame => write!(f, "Frame"), - PoBEvent::KeyDown(_, _) => write!(f, "KeyDown"), - PoBEvent::KeyUp(_) => write!(f, "KeyUp"), - PoBEvent::Char(_) => write!(f, "Char"), - PoBEvent::SubFinished { .. } => write!(f, "SubFinished"), - PoBEvent::SubError { .. } => write!(f, "SubError"), + Self::Init => write!(f, "Init"), + Self::Exit => write!(f, "Exit"), + Self::Frame => write!(f, "Frame"), + Self::KeyDown(_, _) => write!(f, "KeyDown"), + Self::KeyUp(_) => write!(f, "KeyUp"), + Self::Char(_) => write!(f, "Char"), + Self::SubFinished { .. } => write!(f, "SubFinished"), + Self::SubError { .. } => write!(f, "SubError"), } } } @@ -176,7 +176,7 @@ impl LuaInstance { }) } - fn create_lua_state(script_dir: &PathBuf) -> LuaResult { + fn create_lua_state(script_dir: &Path) -> LuaResult { // SAFETY: use `unsafe_new` to allow loading of C modules let lua = unsafe { Lua::unsafe_new() }; @@ -308,7 +308,7 @@ impl LuaInstance { } /// Adds "${script_dir}/lua" to package path - pub fn register_package_paths(lua: &Lua, script_dir: &PathBuf) -> LuaResult<()> { + 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")?; package_path.push(';'); diff --git a/src/main.rs b/src/main.rs index 39e2f77..c3a15b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,10 +59,10 @@ fn find_nearby_launch_script() -> Option { } for candidate in candidates { - if candidate.try_exists().is_ok_and(|exists| exists) { - if let Some(Ok(candidate)) = candidate.parent().map(Path::canonicalize) { - return Some(candidate); - } + if candidate.try_exists().is_ok_and(|exists| exists) + && let Some(Ok(candidate)) = candidate.parent().map(Path::canonicalize) + { + return Some(candidate); } } diff --git a/src/math/quad.rs b/src/math/quad.rs index 12d6434..ed85cc1 100644 --- a/src/math/quad.rs +++ b/src/math/quad.rs @@ -92,7 +92,7 @@ where where T: Zero, { - Quad { + Self { p0: Point::zero(), p1: Point::new(size.width, Zero::zero()), p2: Point::new(size.width, size.height), @@ -107,7 +107,7 @@ where { /// Constructor, setting all points to zero. pub fn zero() -> Self { - Quad::new(Point::zero(), Point::zero(), Point::zero(), Point::zero()) + Self::new(Point::zero(), Point::zero(), Point::zero(), Point::zero()) } } diff --git a/src/mode.rs b/src/mode.rs index 2da4478..9203445 100644 --- a/src/mode.rs +++ b/src/mode.rs @@ -47,29 +47,29 @@ pub enum AppMode { impl AppMode { pub fn frame(&mut self, state: &mut AppState) -> anyhow::Result { match self { - AppMode::Install(mode) => mode.frame(state), - AppMode::PoB(mode) => mode.frame(state), + Self::Install(mode) => mode.frame(state), + Self::PoB(mode) => mode.frame(state), } } pub fn update(&mut self, state: &mut AppState) -> anyhow::Result> { match self { - AppMode::Install(mode) => mode.update(state), - AppMode::PoB(mode) => mode.update(state), + Self::Install(mode) => mode.update(state), + Self::PoB(mode) => mode.update(state), } } pub fn handle_event(&mut self, state: &mut AppState, event: AppEvent) -> anyhow::Result<()> { match self { - AppMode::Install(mode) => mode.handle_event(state, event), - AppMode::PoB(mode) => mode.handle_event(state, event), + Self::Install(mode) => mode.handle_event(state, event), + Self::PoB(mode) => mode.handle_event(state, event), } } pub fn can_exit(&mut self, state: &mut AppState) -> bool { match self { - AppMode::Install(_) => true, - AppMode::PoB(mode) => mode.can_exit(state), + Self::Install(_) => true, + Self::PoB(mode) => mode.can_exit(state), } } } diff --git a/src/renderer.rs b/src/renderer.rs index d812b5e..e531845 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -547,7 +547,7 @@ fn create_sampler(options: TextureOptions, device: &wgpu::Device) -> wgpu::Sampl } /// Adapted from `wgpu::Device::create_texture_with_data`. -/// Doesn't upload any data for mip level > 0 if skip_mipmaps is true. +/// Doesn't upload any data for mip level > 0 if `skip_mipmaps` is true. fn create_texture_with_data( device: &wgpu::Device, queue: &wgpu::Queue, diff --git a/src/renderer/image.rs b/src/renderer/image.rs index 333992e..a0341bc 100644 --- a/src/renderer/image.rs +++ b/src/renderer/image.rs @@ -103,7 +103,7 @@ impl std::fmt::Debug for ImageData { .field("height", &self.height) .field("array_layers", &self.array_layers) .field("mipmap_count", &self.mipmap_count) - .finish() + .finish_non_exhaustive() } } @@ -153,7 +153,7 @@ fn dds_format_to_wgpu(format: dds::Format) -> anyhow::Result wgpu::TextureFormat::Bc3RgbaUnorm, dds::Format::BC7_UNORM => wgpu::TextureFormat::Bc7RgbaUnorm, dds::Format::R8G8B8A8_UNORM => wgpu::TextureFormat::Rgba8Unorm, - _ => anyhow::bail!("Unsupported DDS format: {:?}", format), + _ => anyhow::bail!("Unsupported DDS format: {format:?}"), }) } diff --git a/src/renderer/mipmap.rs b/src/renderer/mipmap.rs index e317e40..71fddb3 100644 --- a/src/renderer/mipmap.rs +++ b/src/renderer/mipmap.rs @@ -2,7 +2,7 @@ /// Assumes data to contain one mip level 0 image for each layer in RGBA format. pub fn generate_mipmap_chain(queue: &wgpu::Queue, texture: &wgpu::Texture, data: &[u8]) { assert!(!texture.format().is_compressed()); - assert!(texture.format().components() == 4); + assert_eq!(texture.format().components(), 4); let size = texture.size(); let block_size = texture.format().block_copy_size(None).unwrap_or(4); diff --git a/src/renderer/primitives.rs b/src/renderer/primitives.rs index a5f12f5..30706c0 100644 --- a/src/renderer/primitives.rs +++ b/src/renderer/primitives.rs @@ -35,13 +35,13 @@ pub enum DrawPrimitive { impl DrawPrimitive { pub fn texture_id(&self) -> TextureId { match self { - DrawPrimitive::Rect(rect_primitive) => rect_primitive + Self::Rect(rect_primitive) => rect_primitive .texture .map_or_else(TextureId::default, |tex| tex.texture_id), - DrawPrimitive::Quad(quad_primitive) => quad_primitive + Self::Quad(quad_primitive) => quad_primitive .texture .map_or_else(TextureId::default, |tex| tex.texture_id), - _ => TextureId::default(), + Self::Text(_) => TextureId::default(), } } } diff --git a/src/renderer/tessellator.rs b/src/renderer/tessellator.rs index e24a74d..debb9ac 100644 --- a/src/renderer/tessellator.rs +++ b/src/renderer/tessellator.rs @@ -57,15 +57,12 @@ impl Tessellator { return; } - let start_new_mesh = match out_clipped_meshes.last() { - None => true, - Some(last_clipped_mesh) => { - // append to previous mesh if clip_rect and texture_id match. - // otherwise, start a new mesh. - !(last_clipped_mesh.clip_rect == clip_rect - && last_clipped_mesh.mesh.texture_id == primitive.texture_id()) - } - }; + let start_new_mesh = out_clipped_meshes.last().is_none_or(|last_clipped_mesh| { + // append to previous mesh if clip_rect and texture_id match. + // otherwise, start a new mesh. + !(last_clipped_mesh.clip_rect == clip_rect + && last_clipped_mesh.mesh.texture_id == primitive.texture_id()) + }); if start_new_mesh { out_clipped_meshes.push(ClippedMesh { @@ -78,17 +75,19 @@ impl Tessellator { match primitive { DrawPrimitive::Rect(rect_primitive) => { - self.convert_rect_primitive(rect_primitive, &mut last_clipped_mesh.mesh) + self.convert_rect_primitive(rect_primitive, &mut last_clipped_mesh.mesh); } DrawPrimitive::Quad(quad_primitive) => { - self.convert_quad_primitive(quad_primitive, &mut last_clipped_mesh.mesh) + self.convert_quad_primitive(quad_primitive, &mut last_clipped_mesh.mesh); + } + DrawPrimitive::Text(text_primitive) => { + self.convert_text_primitive( + text_primitive, + font_atlas_size, + pixels_per_point, + &mut last_clipped_mesh.mesh, + ); } - DrawPrimitive::Text(text_primitive) => self.convert_text_primitive( - text_primitive, - font_atlas_size, - pixels_per_point, - &mut last_clipped_mesh.mesh, - ), } // This can be empty if a new mesh was started but the conversion from a text primitive diff --git a/src/renderer/textures.rs b/src/renderer/textures.rs index 72e7d29..5f43d04 100644 --- a/src/renderer/textures.rs +++ b/src/renderer/textures.rs @@ -103,7 +103,7 @@ impl TextureManager { id } - /// Reserves a new TextureId for later assignment. + /// Reserves a new `TextureId` for later assignment. pub fn reserve(&mut self, name: String, options: TextureOptions) -> TextureId { let id = self.next_id; self.next_id += 1; @@ -228,7 +228,7 @@ impl WrappedTextureManager { .unwrap() .set(id, ImageDelta::new(image, options)); } - Err(e) => log::warn!("Unable to load image fron {}: {}", &image_path, e), + Err(e) => log::warn!("Unable to load image fron {image_path}: {e}"), }); TextureHandle::new(manager, id) @@ -239,7 +239,7 @@ impl WrappedTextureManager { TextureHandle::new(manager, id) } Err(e) => { - log::warn!("Unable to load image fron {}: {}", &image_path, e); + log::warn!("Unable to load image fron {image_path}: {e}"); bail!(e); } } @@ -265,7 +265,7 @@ impl WrappedTextureManager { .unwrap() .set(texture_id, ImageDelta::new(image, options)); } - Err(e) => log::warn!("Unable to load image fron {}: {}", &image_path, e), + Err(e) => log::warn!("Unable to load image fron {image_path}: {e}"), }); } else { match load_image_file(Path::new(&image_path)) { @@ -276,7 +276,7 @@ impl WrappedTextureManager { .set(texture_id, ImageDelta::new(image, options)); } Err(e) => { - log::warn!("Unable to load image fron {}: {}", &image_path, e); + log::warn!("Unable to load image fron {image_path}: {e}"); bail!(e); } } diff --git a/src/subscript.rs b/src/subscript.rs index cc69d1c..768e05b 100644 --- a/src/subscript.rs +++ b/src/subscript.rs @@ -65,14 +65,11 @@ impl SubscriptManager { self.scripts.retain_mut(|subscript| { subscript.handle_calls(lua); - if let Some(event) = subscript.try_join() { + subscript.try_join().is_none_or(|event| { results.push(event); // subscript has finished or errored, remove it false - } else { - // subscript has not finished yet, keep it - true - } + }) }); results @@ -149,7 +146,7 @@ impl Subscript { }) .unwrap(); // this blocks until we receive return values - let return_values = rx_return.recv().map_err(|e| anyhow!("{}", e))??; + let return_values = rx_return.recv().map_err(|e| anyhow!("{e}"))??; Ok(return_values) })?, )?; @@ -165,7 +162,7 @@ impl Subscript { function_name: function_name.clone(), arguments: args.try_into()?, }) - .map_err(|e| anyhow!("{}", e))?; + .map_err(|e| anyhow!("{e}"))?; Ok(()) })?, )?; @@ -227,12 +224,7 @@ impl Subscript { } fn try_join(&mut self) -> Option { - if self - .handle - .as_ref() - .map(|h| h.is_finished()) - .unwrap_or(false) - { + if self.handle.as_ref().is_some_and(JoinHandle::is_finished) { let event = match self.handle.take().unwrap().join() { Ok(Ok(return_values)) => SubscriptResult::SubscriptFinished { id: self.id, @@ -272,14 +264,14 @@ pub fn register_subscript_globals( )| { let blocking_calls = func_list .split(',') - .map(|s| s.trim()) + .map(str::trim) .filter(|&s| !s.is_empty()) .map(String::from) .collect(); let nonblocking_calls = sub_list .split(',') - .map(|s| s.trim()) + .map(str::trim) .filter(|&s| !s.is_empty()) .map(String::from) .collect(); @@ -351,7 +343,7 @@ impl TryFrom for NativeMultiValue { }) .collect::, _>>()?; - Ok(NativeMultiValue(native)) + Ok(Self(native)) } } diff --git a/src/window.rs b/src/window.rs index 9da6bd8..ec645eb 100644 --- a/src/window.rs +++ b/src/window.rs @@ -81,11 +81,9 @@ impl WindowState { } pub fn get_clipboard_text(&mut self) -> Option { - if let Some(clipboard) = &mut self.clipboard { - clipboard.get_text() - } else { - None - } + self.clipboard + .as_mut() + .and_then(|clipboard| clipboard.get_text()) } pub fn request_redraw(&self) {