From e3a15856e7671b2aad187ab1831d631017a8cc0f Mon Sep 17 00:00:00 2001 From: novenary Date: Tue, 16 May 2023 16:13:07 +0300 Subject: [PATCH] Fix clippy warnings Also run clippy in CI. --- .github/workflows/rust.yml | 2 ++ shell.nix | 1 + src/main.rs | 4 ++-- src/xwrap.rs | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1f90aee..3b434ef 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,5 +26,7 @@ jobs: run: cargo fmt -- --check - name: Build run: cargo build --verbose + - name: clippy + run: cargo clippy -- -D warnings - name: Run tests run: cargo test --verbose diff --git a/shell.nix b/shell.nix index 0b9051c..a3a95da 100644 --- a/shell.nix +++ b/shell.nix @@ -10,6 +10,7 @@ in pkgs.mkShell { p.rust-analyzer p.rustc p.rustfmt + p.clippy p.xorg.libX11 p.xorg.libXrandr diff --git a/src/main.rs b/src/main.rs index 13ce76d..16dca2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,7 @@ fn run() -> i32 { let output_ext = matches .opt_str("f") - .unwrap_or("png".to_string()) + .unwrap_or_else(|| "png".to_string()) .to_lowercase(); let output_format = match output_ext.as_ref() { "png" => image::ImageOutputFormat::Png, @@ -176,7 +176,7 @@ fn run() -> i32 { } }; - let mut image = match image.into_image_buffer() { + let mut image = match image.to_image_buffer() { Some(i) => i, None => { eprintln!( diff --git a/src/xwrap.rs b/src/xwrap.rs index 7f6263f..19aa7ea 100644 --- a/src/xwrap.rs +++ b/src/xwrap.rs @@ -91,8 +91,8 @@ impl Display { } util::Rect { - x: x, - y: y, + x, + y, w: attrs.width, h: attrs.height, } @@ -125,7 +125,7 @@ impl Display { None } else { Some(ScreenRectIter { - dpy: &self, + dpy: self, res: xrr_res, crtcs: slice::from_raw_parts((*xrr_res).crtcs, (*xrr_res).ncrtc as usize), i: 0, @@ -176,11 +176,11 @@ impl Image { } } - pub fn into_image_buffer(&self) -> Option { + pub fn to_image_buffer(&self) -> Option { let img = unsafe { &*self.handle }; if (img.red_mask, img.green_mask, img.blue_mask) == (0xF800, 0x07E0, 0x001F) { - return self.into_image_buffer_rgb565(); + return self.to_image_buffer_rgb565(); } let bytes_per_pixel = match (img.depth, img.bits_per_pixel) { @@ -233,7 +233,7 @@ impl Image { )) } - fn into_image_buffer_rgb565(&self) -> Option { + fn to_image_buffer_rgb565(&self) -> Option { let img = unsafe { &*self.handle }; if img.depth != 16 || img.bits_per_pixel != 16 { @@ -300,8 +300,8 @@ impl<'a> Iterator for ScreenRectIter<'a> { //Some((w as i32, h as i32, x as i32, y as i32)) Some(util::Rect { - x: x, - y: y, + x, + y, w: w as i32, h: h as i32, }) @@ -332,8 +332,8 @@ pub fn parse_geometry(g: ffi::CString) -> util::Rect { ); util::Rect { - x: x, - y: y, + x, + y, w: w as i32, h: h as i32, }