Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
Also run clippy in CI.
  • Loading branch information
9ary committed May 16, 2023
1 parent 8a37672 commit e3a1585
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in pkgs.mkShell {
p.rust-analyzer
p.rustc
p.rustfmt
p.clippy

p.xorg.libX11
p.xorg.libXrandr
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!(
Expand Down
20 changes: 10 additions & 10 deletions src/xwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl Display {
}

util::Rect {
x: x,
y: y,
x,
y,
w: attrs.width,
h: attrs.height,
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -176,11 +176,11 @@ impl Image {
}
}

pub fn into_image_buffer(&self) -> Option<RgbaImage> {
pub fn to_image_buffer(&self) -> Option<RgbaImage> {
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) {
Expand Down Expand Up @@ -233,7 +233,7 @@ impl Image {
))
}

fn into_image_buffer_rgb565(&self) -> Option<RgbaImage> {
fn to_image_buffer_rgb565(&self) -> Option<RgbaImage> {
let img = unsafe { &*self.handle };

if img.depth != 16 || img.bits_per_pixel != 16 {
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit e3a1585

Please sign in to comment.