From 7e198ec953017dd56ae9bf900d295c6d8ff5a536 Mon Sep 17 00:00:00 2001 From: Oliver Walter Date: Fri, 5 Sep 2025 00:57:30 +0200 Subject: [PATCH] release clippy fixes --- src/app.rs | 2 +- src/cache/mod.rs | 6 ++++++ src/display/image_sim.rs | 22 ++++++++++++++-------- src/display/simulator.rs | 24 +++++++++++++++--------- src/epd/color.rs | 2 +- src/epd/graphics.rs | 6 +++--- src/killinfo.rs | 16 ++++++++++------ src/lib.rs | 2 +- src/main.rs | 4 ++-- src/services/esi_static.rs | 6 ++++++ src/services/zkill.rs | 6 ++++++ 11 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/app.rs b/src/app.rs index 38b2eb4..2eb8a05 100644 --- a/src/app.rs +++ b/src/app.rs @@ -208,6 +208,6 @@ where } } - return false; + false } } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 237e3ab..2530854 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -9,6 +9,12 @@ pub struct SimpleCache { collection: BTreeMap, } +impl Default for SimpleCache { + fn default() -> Self { + Self::new() + } +} + impl SimpleCache { /// Create new Empty Cache pub fn new() -> Self { diff --git a/src/display/image_sim.rs b/src/display/image_sim.rs index 16c7d9a..fe98827 100644 --- a/src/display/image_sim.rs +++ b/src/display/image_sim.rs @@ -23,6 +23,12 @@ pub struct ImageSimulator { buffer: Framebuffer, } +impl Default for ImageSimulator { + fn default() -> Self { + Self::new() + } +} + impl ImageSimulator { pub fn new() -> Self { Self { @@ -63,7 +69,7 @@ impl ImageSimulator { // Draw Alliance logo (64x64) if present if let Some(alliance) = &kill.victim.alliance { let bw_vec = rgb_to_bw_dithered(&alliance.logo); - let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -72,7 +78,7 @@ impl ImageSimulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgb_to_bw_dithered(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); @@ -132,7 +138,7 @@ impl ImageSimulator { // Draw Alliance logo (64x64) if present if let Some(character) = &kill.victim.character { let bw_vec = rgb_to_bw_dithered(&character.portrait); - let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -141,7 +147,7 @@ impl ImageSimulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgb_to_bw_dithered(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); @@ -234,7 +240,7 @@ impl KillDisplay for ImageSimulator { // Draw Alliance logo (64x64) if present if let Some(alliance) = &kill.victim.alliance { let bw_vec = rgb_to_bw_dithered(&alliance.logo); - let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -243,7 +249,7 @@ impl KillDisplay for ImageSimulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgb_to_bw_dithered(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); @@ -303,7 +309,7 @@ impl KillDisplay for ImageSimulator { // Draw Alliance logo (64x64) if present if let Some(character) = &kill.victim.character { let bw_vec = rgb_to_bw_dithered(&character.portrait); - let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -312,7 +318,7 @@ impl KillDisplay for ImageSimulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgb_to_bw_dithered(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); diff --git a/src/display/simulator.rs b/src/display/simulator.rs index 9fc7c77..82fe69d 100644 --- a/src/display/simulator.rs +++ b/src/display/simulator.rs @@ -22,6 +22,12 @@ pub struct Simulator { window: Window, } +impl Default for Simulator { + fn default() -> Self { + Self::new() + } +} + impl Simulator { pub fn new() -> Self { let display = SimulatorDisplay::::new(Size::new(WIDTH as u32, HEIGHT as u32)); @@ -60,7 +66,7 @@ impl Simulator { // Draw Alliance logo (64x64) if present if let Some(alliance) = &kill.victim.alliance { let bw_vec = rgbimage_to_gray8(&alliance.logo); - let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -69,7 +75,7 @@ impl Simulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgbimage_to_gray8(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); @@ -129,7 +135,7 @@ impl Simulator { // Draw Alliance logo (64x64) if present if let Some(character) = &kill.victim.character { let bw_vec = rgbimage_to_gray8(&character.portrait); - let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -138,7 +144,7 @@ impl Simulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgbimage_to_gray8(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); @@ -230,7 +236,7 @@ impl KillDisplay for Simulator { // Draw Alliance logo (64x64) if present if let Some(alliance) = &kill.victim.alliance { let bw_vec = rgbimage_to_gray8(&alliance.logo); - let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, alliance.logo.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -239,7 +245,7 @@ impl KillDisplay for Simulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgbimage_to_gray8(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); @@ -299,7 +305,7 @@ impl KillDisplay for Simulator { // Draw Alliance logo (64x64) if present if let Some(character) = &kill.victim.character { let bw_vec = rgbimage_to_gray8(&character.portrait); - let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, character.portrait.width()); Image::new(&logo_raw, Point::new(x, y)) .draw(&mut self.buffer) .ok(); @@ -308,7 +314,7 @@ impl KillDisplay for Simulator { // Draw Ship icon (64x64) if present if let Some(ship) = &kill.victim.ship { let bw_vec = rgbimage_to_gray8(&ship.icon); - let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width() as u32); + let logo_raw = ImageRaw::::new(&bw_vec, ship.icon.width()); Image::new(&logo_raw, Point::new(x + 64 + 4, current_y)) .draw(&mut self.buffer) .ok(); @@ -375,5 +381,5 @@ fn rgbimage_to_gray8(raw_img: &RgbImage) -> Vec { gray_data.push(luma); } - return gray_data; + gray_data } diff --git a/src/epd/color.rs b/src/epd/color.rs index 5ca91ed..7a1b80c 100644 --- a/src/epd/color.rs +++ b/src/epd/color.rs @@ -85,7 +85,7 @@ pub trait ColorType { /// Return values are : /// * .0 is the mask used to exclude this pixel from the byte (eg: 0x7F in BiColor) /// * .1 are the bits used to set the color in the byte (eg: 0x80 in BiColor) - /// this is u16 because we set 2 bytes in case of split buffer + /// this is u16 because we set 2 bytes in case of split buffer fn bitmask(&self, bwrbit: bool, pos: u32) -> (u8, u16); } diff --git a/src/epd/graphics.rs b/src/epd/graphics.rs index 7620168..7bab5f7 100644 --- a/src/epd/graphics.rs +++ b/src/epd/graphics.rs @@ -21,7 +21,7 @@ pub enum DisplayRotation { /// count the number of bytes per line knowing that it may contains padding bits const fn line_bytes(width: u32, bits_per_pixel: usize) -> usize { // round to upper 8 bit count - (width as usize * bits_per_pixel + 7) / 8 + (width as usize * bits_per_pixel).div_ceil(8) } /// Display buffer used for drawing with embedded graphics @@ -30,10 +30,10 @@ const fn line_bytes(width: u32, bits_per_pixel: usize) -> usize { /// - WIDTH: width in pixel when display is not rotated /// - HEIGHT: height in pixel when display is not rotated /// - BWRBIT: mandatory value of the B/W when chromatic bit is set, can be any value for non -/// tricolor epd +/// tricolor epd /// - COLOR: color type used by the target display /// - BYTECOUNT: This is redundant with previous data and should be removed when const generic -/// expressions are stabilized +/// expressions are stabilized /// /// More on BWRBIT: /// diff --git a/src/killinfo.rs b/src/killinfo.rs index 264dbd2..c1b824a 100644 --- a/src/killinfo.rs +++ b/src/killinfo.rs @@ -47,6 +47,12 @@ pub struct KillInfoBuilder { corporation_id: u32, } +impl Default for KillInfoBuilder { + fn default() -> Self { + Self::new() + } +} + impl KillInfoBuilder { /// Creates a new builder with default settings. pub fn new() -> KillInfoBuilder { @@ -79,16 +85,14 @@ impl KillInfoBuilder { let main_attacker: Option = self.find_main_attacker(&attacker_list).and_then(|a| { // Try to build the Individual. If it fails, return None - match Individual::build_with_esi( + Individual::build_with_esi( esi, a.character_id, a.corporation_id, a.alliance_id, a.ship_id, - ) { - Ok(ind) => Some(ind), - Err(_) => None, // ignore errors here - } + ) + .ok() }); let victim = Individual::build_with_esi( @@ -118,7 +122,7 @@ impl KillInfoBuilder { /// the attacker with the highest damage done. pub fn find_main_attacker( &self, - attacker_list: &Vec, + attacker_list: &[KillmailAttacker], ) -> Option { if attacker_list.is_empty() { return None; diff --git a/src/lib.rs b/src/lib.rs index 207e1ff..5295c21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub mod services; /// \[XXXXX210\]\[76543210\]...\[76543210\] | height /// \[XXXXX210\]\[76543210\]...\[76543210\] v pub const fn buffer_len(width: usize, height: usize) -> usize { - (width + 7) / 8 * height + width.div_ceil(8) * height } use embedded_hal::spi::{Mode, Phase, Polarity}; diff --git a/src/main.rs b/src/main.rs index e8d16e6..b4231d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,10 +26,10 @@ pub mod services; pub mod epd; pub const fn buffer_len(width: usize, height: usize) -> usize { - (width + 7) / 8 * height + width.div_ceil(8) * height } -fn main() -> () { +fn main() { // Pick the display based on compile-time feature #[cfg(feature = "simulator")] let display = display::Simulator::new(); diff --git a/src/services/esi_static.rs b/src/services/esi_static.rs index 4246103..483799a 100644 --- a/src/services/esi_static.rs +++ b/src/services/esi_static.rs @@ -116,6 +116,12 @@ pub struct EsiClient { ship_image_cache: ImageCache, } +impl Default for EsiClient { + fn default() -> Self { + Self::new() + } +} + impl EsiClient { /// Creates a new `EsiClient` instance with default configuration. /// diff --git a/src/services/zkill.rs b/src/services/zkill.rs index c5875a7..9066cc2 100644 --- a/src/services/zkill.rs +++ b/src/services/zkill.rs @@ -131,6 +131,12 @@ pub struct ZkillClient { client: Client, } +impl Default for ZkillClient { + fn default() -> Self { + Self::new() + } +} + impl ZkillClient { /// Creates a new [`ZkillClient`] with a configured `reqwest::Client`. ///