From 02c95bece25fe169497a7f210e10cd8da9b299cb Mon Sep 17 00:00:00 2001 From: Ralf Fuest Date: Tue, 1 Jul 2025 19:23:18 +0200 Subject: [PATCH] Fix clippy warnings --- bdf-parser/src/glyph.rs | 2 +- bdf-parser/src/properties.rs | 2 +- eg-bdf-examples/examples/hello.rs | 2 +- eg-font-converter/src/eg_bdf_font.rs | 6 +++--- eg-font-converter/src/lib.rs | 29 ++++++++++++++-------------- eg-font-converter/src/main.rs | 2 +- eg-font-converter/src/mono_font.rs | 8 ++++---- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/bdf-parser/src/glyph.rs b/bdf-parser/src/glyph.rs index 6006a51..23134a2 100644 --- a/bdf-parser/src/glyph.rs +++ b/bdf-parser/src/glyph.rs @@ -80,7 +80,7 @@ impl Glyph { return None; } - let bytes_per_row = (width + 7) / 8; + let bytes_per_row = width.div_ceil(8); let byte_offset = x / 8; let bit_mask = 0x80 >> (x % 8); diff --git a/bdf-parser/src/properties.rs b/bdf-parser/src/properties.rs index 3b11e72..06214f8 100644 --- a/bdf-parser/src/properties.rs +++ b/bdf-parser/src/properties.rs @@ -157,7 +157,7 @@ impl Properties { // Convert vector of properties into a HashMap let properties = properties .map(|p| p.iter().cloned().collect()) - .unwrap_or_else(HashMap::new); + .unwrap_or_default(); Self { properties } }, diff --git a/eg-bdf-examples/examples/hello.rs b/eg-bdf-examples/examples/hello.rs index 734318b..3a76f8a 100644 --- a/eg-bdf-examples/examples/hello.rs +++ b/eg-bdf-examples/examples/hello.rs @@ -1,4 +1,4 @@ -use eg_bdf::{BdfGlyph, BdfTextStyle}; +use eg_bdf::BdfTextStyle; use embedded_graphics::{ mono_font::MonoTextStyle, pixelcolor::Rgb888, diff --git a/eg-font-converter/src/eg_bdf_font.rs b/eg-font-converter/src/eg_bdf_font.rs index d51238c..0f5d387 100644 --- a/eg-font-converter/src/eg_bdf_font.rs +++ b/eg-font-converter/src/eg_bdf_font.rs @@ -105,7 +105,7 @@ impl EgBdfOutput { }); let comments = self.font.comments.iter().map(|comment| { - let comment = format!(" {}", comment); + let comment = format!(" {comment}"); quote!( #[doc = #comment] ) @@ -157,8 +157,8 @@ impl EgBdfOutput { pub fn save>(&self, output_directory: P) -> io::Result<()> { let output_directory = output_directory.as_ref(); - fs::write(self.font.rust_file_path(output_directory), &self.rust())?; - fs::write(self.font.data_file_path(output_directory), &self.data())?; + fs::write(self.font.rust_file_path(output_directory), self.rust())?; + fs::write(self.font.data_file_path(output_directory), self.data())?; Ok(()) } diff --git a/eg-font-converter/src/lib.rs b/eg-font-converter/src/lib.rs index 2dc8156..4d4ca21 100644 --- a/eg-font-converter/src/lib.rs +++ b/eg-font-converter/src/lib.rs @@ -17,16 +17,14 @@ //! ```no_run //! use eg_font_converter::{FontConverter, Mapping}; //! -//! fn main() { -//! let out_dir = std::env::var_os("OUT_DIR").unwrap(); +//! let out_dir = std::env::var_os("OUT_DIR").unwrap(); //! -//! let font_6x10 = FontConverter::new("examples/6x10.bdf", "FONT_6X10_AZ") -//! .glyphs('A'..='Z') -//! .convert_mono_font() -//! .unwrap(); +//! let font_6x10 = FontConverter::new("examples/6x10.bdf", "FONT_6X10_AZ") +//! .glyphs('A'..='Z') +//! .convert_mono_font() +//! .unwrap(); //! -//! font_6x10.save(&out_dir).unwrap(); -//! } +//! font_6x10.save(&out_dir).unwrap(); //! ``` //! //! And then use the [`include!`] macro to import the generated code into your project: @@ -264,12 +262,13 @@ impl<'a> FontConverter<'a> { let bdf = match &self.bdf { FileOrData::File(file) => { let data = std::fs::read(file) - .with_context(|| format!("couldn't read BDF file from {:?}", file))?; + .with_context(|| format!("couldn't read BDF file from {file:?}"))?; - ParserBdfFont::parse(&data).with_context(|| format!("couldn't parse BDF file"))? + ParserBdfFont::parse(&data) + .with_context(|| "couldn't parse BDF file".to_string())? } FileOrData::Data(data) => { - ParserBdfFont::parse(data).with_context(|| format!("couldn't parse BDF file"))? + ParserBdfFont::parse(data).with_context(|| "couldn't parse BDF file".to_string())? } }; @@ -439,7 +438,7 @@ impl Font { } fn data_file_path(&self, output_directory: &Path) -> PathBuf { - output_directory.join(&self.data_file()) + output_directory.join(self.data_file()) } } @@ -518,8 +517,10 @@ pub enum Visibility { PubIn(String), } -impl ToString for Visibility { - fn to_string(&self) -> String { +impl Visibility { + // TODO: is Visibility even used anymore? + #[allow(unused)] + fn to_rust(&self) -> String { match self { Visibility::Private => "", Visibility::Pub => "pub", diff --git a/eg-font-converter/src/main.rs b/eg-font-converter/src/main.rs index dfcc6cc..7c5d74e 100644 --- a/eg-font-converter/src/main.rs +++ b/eg-font-converter/src/main.rs @@ -121,7 +121,7 @@ fn main() { } if let Err(e) = convert(&args) { - eprintln!("Error: {:#}", e); + eprintln!("Error: {e:#}"); std::process::exit(1); } } diff --git a/eg-font-converter/src/mono_font.rs b/eg-font-converter/src/mono_font.rs index 2a91f05..d33d542 100644 --- a/eg-font-converter/src/mono_font.rs +++ b/eg-font-converter/src/mono_font.rs @@ -38,7 +38,7 @@ impl MonoFontOutput { let glyphs_per_row = 16; //TODO: make configurable let columns = glyphs_per_row; // TODO: allow smaller column count - let rows = (font.glyphs.len() + (glyphs_per_row - 1)) / glyphs_per_row; + let rows = font.glyphs.len().div_ceil(glyphs_per_row); let character_size = bdf.bounding_box().size; let character_spacing = 0; @@ -149,7 +149,7 @@ impl MonoFontOutput { }; let comments = self.font.comments.iter().map(|comment| { - let comment = format!(" {}", comment); + let comment = format!(" {comment}"); quote!( #[doc = #comment] ) @@ -193,8 +193,8 @@ impl MonoFontOutput { pub fn save>(&self, output_directory: P) -> io::Result<()> { let output_directory = output_directory.as_ref(); - fs::write(self.font.rust_file_path(output_directory), &self.rust())?; - fs::write(self.font.data_file_path(output_directory), &self.data())?; + fs::write(self.font.rust_file_path(output_directory), self.rust())?; + fs::write(self.font.data_file_path(output_directory), self.data())?; Ok(()) }