From 3d001fae9938099987088db0a82d6ad18129934a Mon Sep 17 00:00:00 2001 From: akida31 Date: Fri, 9 Feb 2024 09:02:34 +0100 Subject: [PATCH] fix let_underscore_lock lint [Recently][1] the [fix_underscore_lock][2] lint was improved and throws now (as of the upcoming rust 1.77) an error. Therefore I created separate methods for locking only `WallpaperInner`. An alternative could be that the `_` is converted to `_temp` and then the next statement could be `drop(_temp)` to stay with the current behaviour but silence the lint. [1]: https://github.com/rust-lang/rust/pull/119710 [2]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_lint/let_underscore/static.LET_UNDERSCORE_LOCK.html --- daemon/src/wallpaper.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/daemon/src/wallpaper.rs b/daemon/src/wallpaper.rs index 0df141b9..0548bdf3 100644 --- a/daemon/src/wallpaper.rs +++ b/daemon/src/wallpaper.rs @@ -143,7 +143,7 @@ impl Wallpaper { } pub fn get_dimensions(&self) -> (u32, u32) { - let (inner, _) = self.lock(); + let inner = self.lock_inner(); let width = inner.width.get() as u32; let height = inner.height.get() as u32; let scale_factor = inner.scale_factor.get() as u32; @@ -156,10 +156,20 @@ impl Wallpaper { } #[inline] - fn lock_inner_mut(&self) -> (RwLockWriteGuard, MutexGuard) { + fn lock_mut(&self) -> (RwLockWriteGuard, MutexGuard) { (self.inner.write().unwrap(), self.pool.lock().unwrap()) } + #[inline] + fn lock_inner(&self) -> RwLockReadGuard { + self.inner.read().unwrap() + } + + #[inline] + fn lock_inner_mut(&self) -> RwLockWriteGuard { + self.inner.write().unwrap() + } + pub fn canvas_change(&self, f: F) -> T where F: FnOnce(&mut [u8]) -> T, @@ -182,7 +192,7 @@ impl Wallpaper { #[inline] pub fn get_img_info(&self) -> BgImg { - self.lock().0.img.clone() + self.lock_inner().img.clone() } #[inline] @@ -215,7 +225,7 @@ impl Wallpaper { pub fn set_img_info(&self, img_info: BgImg) { log::debug!("output {} - drawing: {}", self.output_id, img_info); - self.lock_inner_mut().0.img = img_info; + self.lock_inner_mut().img = img_info; } pub fn draw(&self) { @@ -244,7 +254,7 @@ impl Wallpaper { if let Some(s) = scale_factor { self.layer_surface.set_buffer_scale(s.get() as u32).unwrap(); } - let (mut inner, mut pool) = self.lock_inner_mut(); + let (mut inner, mut pool) = self.lock_mut(); let width = width.unwrap_or(inner.width); let height = height.unwrap_or(inner.height); let scale_factor = scale_factor.unwrap_or(inner.scale_factor);