diff --git a/src/lib.rs b/src/lib.rs index ce5894f7..5f2214cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ +#![cfg_attr(feature="dev", feature(plugin))] +#![cfg_attr(feature="dev", plugin(clippy))] +#![cfg_attr(feature="dev", allow(module_inception))] + extern crate bit_vec; extern crate byteorder; extern crate crc; @@ -483,8 +487,7 @@ fn optimize_png(mut png: &mut png::PngData, file_original_size: usize, opts: &Op let best: Mutex> = Mutex::new(None); let combinations = filter.len() * compression.len() * memory.len() * strategies.len(); let mut results: Vec<(u8, u8, u8, u8)> = Vec::with_capacity(combinations); - let filters: Mutex>> = - Mutex::new(HashMap::with_capacity(filter.len())); + let filters: Mutex>> = Mutex::new(HashMap::with_capacity(filter.len())); if opts.verbosity.is_some() { writeln!(&mut stderr(), "Trying: {} combinations", combinations).ok(); } @@ -606,31 +609,25 @@ fn optimize_png(mut png: &mut png::PngData, file_original_size: usize, opts: &Op fn perform_reductions(png: &mut png::PngData, opts: &Options) -> bool { let mut something_changed = false; - if opts.palette_reduction { - if png.reduce_palette() { - something_changed = true; - if opts.verbosity == Some(1) { - report_reduction(png); - } - }; + if opts.palette_reduction && png.reduce_palette() { + something_changed = true; + if opts.verbosity == Some(1) { + report_reduction(png); + } } - if opts.bit_depth_reduction { - if png.reduce_bit_depth() { - something_changed = true; - if opts.verbosity == Some(1) { - report_reduction(png); - } - }; + if opts.bit_depth_reduction && png.reduce_bit_depth() { + something_changed = true; + if opts.verbosity == Some(1) { + report_reduction(png); + } } - if opts.color_type_reduction { - if png.reduce_color_type() { - something_changed = true; - if opts.verbosity == Some(1) { - report_reduction(png); - } - }; + if opts.color_type_reduction && png.reduce_color_type() { + something_changed = true; + if opts.verbosity == Some(1) { + report_reduction(png); + } } if something_changed && opts.verbosity.is_some() { @@ -668,15 +665,15 @@ fn report_reduction(png: &png::PngData) { /// Strip headers from the `PngData` object, as requested by the passed `Options` fn perform_strip(png: &mut png::PngData, opts: &Options) { - match &opts.strip { + match opts.strip { // Strip headers - &Headers::None => (), - &Headers::Some(ref hdrs) => { + Headers::None => (), + Headers::Some(ref hdrs) => { for hdr in hdrs { png.aux_headers.remove(hdr); } } - &Headers::Safe => { + Headers::Safe => { const PRESERVED_HEADERS: [&'static str; 9] = ["cHRM", "gAMA", "iCCP", "sBIT", "sRGB", "bKGD", "hIST", "pHYs", "sPLT"]; let hdrs = png.aux_headers.keys().cloned().collect::>(); @@ -686,7 +683,7 @@ fn perform_strip(png: &mut png::PngData, opts: &Options) { } } } - &Headers::All => { + Headers::All => { png.aux_headers = HashMap::new(); } } diff --git a/src/main.rs b/src/main.rs index 44e4f7c1..afecfd86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#![cfg_attr(feature="dev", feature(plugin))] +#![cfg_attr(feature="dev", plugin(clippy))] + extern crate oxipng; extern crate clap; extern crate regex; diff --git a/src/png.rs b/src/png.rs index 7bdc25f3..b5f32bbd 100644 --- a/src/png.rs +++ b/src/png.rs @@ -300,24 +300,24 @@ impl PngData { // Ancillary headers for (key, header) in self.aux_headers .iter() - .filter(|&(ref key, _)| !(**key == "bKGD" || **key == "hIST" || **key == "tRNS")) { + .filter(|&(key, _)| !(*key == "bKGD" || *key == "hIST" || *key == "tRNS")) { write_png_block(key.as_bytes(), header, &mut output); } // Palette if let Some(ref palette) = self.palette { - write_png_block(b"PLTE", &palette, &mut output); + write_png_block(b"PLTE", palette, &mut output); if let Some(ref transparency_palette) = self.transparency_palette { // Transparency pixel - write_png_block(b"tRNS", &transparency_palette, &mut output); + write_png_block(b"tRNS", transparency_palette, &mut output); } } else if let Some(ref transparency_pixel) = self.transparency_pixel { // Transparency pixel - write_png_block(b"tRNS", &transparency_pixel, &mut output); + write_png_block(b"tRNS", transparency_pixel, &mut output); } // Special ancillary headers that need to come after PLTE but before IDAT for (key, header) in self.aux_headers .iter() - .filter(|&(ref key, _)| **key == "bKGD" || **key == "hIST" || **key == "tRNS") { + .filter(|&(key, _)| *key == "bKGD" || *key == "hIST" || *key == "tRNS") { write_png_block(key.as_bytes(), header, &mut output); } // IDAT data @@ -547,7 +547,7 @@ impl PngData { } let unused: Vec = - (0..indexed_palette.len() as u8).filter(|i| !seen.contains(&i)).collect(); + (0..indexed_palette.len() as u8).filter(|i| !seen.contains(i)).collect(); // Remove unused palette indices self.do_palette_reduction(&unused, &mut index_map, &mut indexed_palette);