Fix all the clippy lints

This commit is contained in:
Gwilym Kuiper 2021-04-20 22:56:47 +01:00
parent 62e0c346c5
commit 5234c7181e
5 changed files with 18 additions and 17 deletions

View file

@ -2,7 +2,7 @@ use std::env;
use agb_image_converter::{convert_image, ImageConverterConfig, TileSize};
fn main() -> () {
fn main() {
let args: Vec<_> = env::args().collect();
let file_path = &args[1];
@ -12,6 +12,5 @@ fn main() -> () {
tile_size: TileSize::Tile8,
input_image: file_path.into(),
output_file: output_path.into(),
output_name: "HELLO".to_owned(),
});
}

View file

@ -10,7 +10,7 @@ impl Colour {
Colour { r, g, b }
}
pub fn to_rgb15(&self) -> u16 {
pub fn to_rgb15(self) -> u16 {
let (r, g, b) = (self.r as u16, self.g as u16, self.b as u16);
((r >> 3) & 31) | (((g >> 3) & 31) << 5) | (((b >> 3) & 31) << 10)
}

View file

@ -18,8 +18,8 @@ pub enum TileSize {
}
impl TileSize {
fn to_size(&self) -> usize {
match &self {
fn to_size(self) -> usize {
match self {
TileSize::Tile8 => 8,
TileSize::Tile16 => 16,
}

View file

@ -107,7 +107,7 @@ impl Palette16Optimiser {
.cloned()
.collect::<HashSet<Palette16>>();
while unsatisfied_palettes.len() > 0 {
while !unsatisfied_palettes.is_empty() {
let palette = self.find_maximal_palette_for(&unsatisfied_palettes, transparent_colour);
for test_palette in unsatisfied_palettes.clone() {
@ -130,8 +130,8 @@ impl Palette16Optimiser {
}
Palette16OptimisationResults {
assignments,
optimised_palettes,
assignments,
}
}

View file

@ -11,9 +11,9 @@ pub(crate) fn generate_code(
image: &Image,
tile_size: TileSize,
) -> io::Result<()> {
write!(
writeln!(
output,
"pub const PALETTE_DATA: &'static [crate::display::palette16::Palette16] = &[\n",
"pub const PALETTE_DATA: &'static [crate::display::palette16::Palette16] = &[",
)?;
for palette in &results.optimised_palettes {
@ -27,12 +27,13 @@ pub(crate) fn generate_code(
write!(output, "0x00000000, ")?;
}
write!(output, "]),\n")?;
writeln!(output, "]),")?;
}
write!(output, "];\n\n")?;
writeln!(output, "];")?;
writeln!(output)?;
write!(output, "pub const TILE_DATA: &'static [u32] = &[\n",)?;
writeln!(output, "pub const TILE_DATA: &'static [u32] = &[",)?;
let tile_size = tile_size.to_size();
@ -43,9 +44,9 @@ pub(crate) fn generate_code(
for x in 0..tiles_x {
let palette_index = results.assignments[y * tiles_x + x];
let palette = &results.optimised_palettes[palette_index];
write!(
writeln!(
output,
" /* {}, {} (palette index {}) */\n",
" /* {}, {} (palette index {}) */",
x, y, palette_index
)?;
@ -68,11 +69,12 @@ pub(crate) fn generate_code(
}
}
write!(output, "\n")?;
writeln!(output)?;
}
}
write!(output, "];\n\n")?;
writeln!(output, "];")?;
writeln!(output)?;
write!(output, "pub const PALETTE_ASSIGNMENT: &'static [u8] = &[")?;
@ -83,7 +85,7 @@ pub(crate) fn generate_code(
write!(output, "{}, ", assignment)?;
}
write!(output, "\n];\n")?;
writeln!(output, "\n];")?;
Ok(())
}