Skip to content

Commit

Permalink
fix let_underscore_lock lint
Browse files Browse the repository at this point in the history
[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]: rust-lang/rust#119710
[2]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_lint/let_underscore/static.LET_UNDERSCORE_LOCK.html
  • Loading branch information
Akida31 committed Feb 9, 2024
1 parent ad3d406 commit 3d001fa
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -156,10 +156,20 @@ impl Wallpaper {
}

#[inline]
fn lock_inner_mut(&self) -> (RwLockWriteGuard<WallpaperInner>, MutexGuard<SlotPool>) {
fn lock_mut(&self) -> (RwLockWriteGuard<WallpaperInner>, MutexGuard<SlotPool>) {
(self.inner.write().unwrap(), self.pool.lock().unwrap())
}

#[inline]
fn lock_inner(&self) -> RwLockReadGuard<WallpaperInner> {
self.inner.read().unwrap()
}

#[inline]
fn lock_inner_mut(&self) -> RwLockWriteGuard<WallpaperInner> {
self.inner.write().unwrap()
}

pub fn canvas_change<F, T>(&self, f: F) -> T
where
F: FnOnce(&mut [u8]) -> T,
Expand All @@ -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]
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3d001fa

Please sign in to comment.