diff --git a/src/lib.rs b/src/lib.rs index ea79f7c9..90090a2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,16 +133,24 @@ pub fn optimize(filepath: &Path, opts: &Options) -> Result<(), String> { let output_data = png.output(); if file_original_size <= output_data.len() { println!("File already optimized"); - return Ok(()) + return Ok(()); } if opts.pretend { println!("Running in pretend mode, no output"); } else { if opts.backup { - match fs::copy(in_file, in_file.with_extension(format!("bak.{}", in_file.extension().unwrap().to_str().unwrap()))) { + match fs::copy(in_file, + in_file.with_extension(format!("bak.{}", + in_file.extension() + .unwrap() + .to_str() + .unwrap()))) { Ok(x) => x, - Err(_) => return Err(format!("Unable to write to backup file at {}", opts.out_file.display())) + Err(_) => { + return Err(format!("Unable to write to backup file at {}", + opts.out_file.display())) + } }; } @@ -150,22 +158,31 @@ pub fn optimize(filepath: &Path, opts: &Options) -> Result<(), String> { let mut buffer = BufWriter::new(io::stdout()); match buffer.write_all(&output_data) { Ok(_) => (), - Err(_) => return Err(format!("Unable to write to stdout")) + Err(_) => return Err(format!("Unable to write to stdout")), } } else { let out_file = match File::create(&opts.out_file) { Ok(x) => x, - Err(_) => return Err(format!("Unable to write to file {}", opts.out_file.display())) + Err(_) => { + return Err(format!("Unable to write to file {}", opts.out_file.display())) + } }; let mut buffer = BufWriter::new(out_file); match buffer.write_all(&output_data) { Ok(_) => println!("Output: {}", opts.out_file.display()), - Err(_) => return Err(format!("Unable to write to file {}", opts.out_file.display())) + Err(_) => { + return Err(format!("Unable to write to file {}", opts.out_file.display())) + } } } } - println!(" IDAT size = {} bytes ({} bytes decrease)", png.idat_data.len(), idat_original_size - png.idat_data.len()); - println!(" file size = {} bytes ({} bytes = {:.2}% decrease)", output_data.len(), file_original_size - output_data.len(), (file_original_size - output_data.len()) as f64 / file_original_size as f64); + println!(" IDAT size = {} bytes ({} bytes decrease)", + png.idat_data.len(), + idat_original_size - png.idat_data.len()); + println!(" file size = {} bytes ({} bytes = {:.2}% decrease)", + output_data.len(), + file_original_size - output_data.len(), + (file_original_size - output_data.len()) as f64 / file_original_size as f64); Ok(()) } diff --git a/src/main.rs b/src/main.rs index 561ef08b..45ef3883 100644 --- a/src/main.rs +++ b/src/main.rs @@ -391,7 +391,8 @@ fn parse_opts_into_struct(matches: &ArgMatches, opts: &mut optipng::Options) -> if !path.exists() { } else if !path.is_dir() { - return Err(format!("{} is an existing file (not a directory), cannot create directory", x)); + return Err(format!("{} is an existing file (not a directory), cannot create directory", + x)); } opts.out_dir = Some(path); } diff --git a/src/png.rs b/src/png.rs index f5d72359..c30817c1 100644 --- a/src/png.rs +++ b/src/png.rs @@ -189,7 +189,7 @@ impl PngData { output.append(&mut ihdr_data); output.write_u32::(crc).ok(); // Ancillary headers - for (key, header) in self.aux_headers.iter() { + for (key, header) in &self.aux_headers { let mut header_data = header.clone(); output.reserve(header_data.len() + 12); output.write_u32::(header_data.len() as u32).ok(); @@ -205,7 +205,7 @@ impl PngData { output.reserve(palette_data.len() + 12); output.write_u32::(palette_data.len() as u32).ok(); let mut type_head = "PLTE".as_bytes().to_owned(); - let crc =crc32::checksum_ieee(&palette_data); + let crc = crc32::checksum_ieee(&palette_data); output.append(&mut type_head); output.append(&mut palette_data); output.write_u32::(crc).ok();