Fix some new nightly Clippy lints and run rustfmt with prettier config

This commit is contained in:
Alejandro González 2024-02-20 19:12:35 +01:00
parent 98fd4de30a
commit 0608ab9cab
No known key found for this signature in database
35 changed files with 191 additions and 189 deletions

View file

@ -3,9 +3,9 @@
extern crate oxipng; extern crate oxipng;
extern crate test; extern crate test;
use oxipng::internal_tests::*;
use oxipng::*;
use std::path::PathBuf; use std::path::PathBuf;
use oxipng::{internal_tests::*, *};
use test::Bencher; use test::Bencher;
#[bench] #[bench]

View file

@ -3,9 +3,9 @@
extern crate oxipng; extern crate oxipng;
extern crate test; extern crate test;
use oxipng::internal_tests::*;
use oxipng::*;
use std::path::PathBuf; use std::path::PathBuf;
use oxipng::{internal_tests::*, *};
use test::Bencher; use test::Bencher;
#[bench] #[bench]

View file

@ -3,9 +3,9 @@
extern crate oxipng; extern crate oxipng;
extern crate test; extern crate test;
use oxipng::internal_tests::*;
use oxipng::*;
use std::path::PathBuf; use std::path::PathBuf;
use oxipng::{internal_tests::*, *};
use test::Bencher; use test::Bencher;
#[bench] #[bench]

View file

@ -3,9 +3,9 @@
extern crate oxipng; extern crate oxipng;
extern crate test; extern crate test;
use oxipng::internal_tests::*;
use oxipng::*;
use std::path::PathBuf; use std::path::PathBuf;
use oxipng::{internal_tests::*, *};
use test::Bencher; use test::Bencher;
#[bench] #[bench]

View file

@ -3,9 +3,9 @@
extern crate oxipng; extern crate oxipng;
extern crate test; extern crate test;
use oxipng::internal_tests::*;
use oxipng::*;
use std::path::PathBuf; use std::path::PathBuf;
use oxipng::{internal_tests::*, *};
use test::Bencher; use test::Bencher;
#[bench] #[bench]

View file

@ -3,10 +3,9 @@
extern crate oxipng; extern crate oxipng;
extern crate test; extern crate test;
use oxipng::internal_tests::*; use std::{num::NonZeroU8, path::PathBuf};
use oxipng::*;
use std::num::NonZeroU8; use oxipng::{internal_tests::*, *};
use std::path::PathBuf;
use test::Bencher; use test::Bencher;
// SAFETY: trivially safe. Stopgap solution until const unwrap is stabilized. // SAFETY: trivially safe. Stopgap solution until const unwrap is stabilized.

View file

@ -1,5 +1,4 @@
use std::sync::atomic::AtomicUsize; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use std::sync::atomic::Ordering::SeqCst;
#[derive(Debug)] #[derive(Debug)]
pub struct AtomicMin { pub struct AtomicMin {

View file

@ -1,6 +1,7 @@
use rgb::{RGB16, RGBA8};
use std::{fmt, fmt::Display}; use std::{fmt, fmt::Display};
use rgb::{RGB16, RGBA8};
use crate::PngError; use crate::PngError;
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]

View file

@ -1,7 +1,7 @@
use crate::atomicmin::AtomicMin;
use crate::{PngError, PngResult};
use libdeflater::*; use libdeflater::*;
use crate::{atomicmin::AtomicMin, PngError, PngResult};
pub fn deflate(data: &[u8], level: u8, max_size: &AtomicMin) -> PngResult<Vec<u8>> { pub fn deflate(data: &[u8], level: u8, max_size: &AtomicMin) -> PngResult<Vec<u8>> {
let mut compressor = Compressor::new(CompressionLvl::new(level.into()).unwrap()); let mut compressor = Compressor::new(CompressionLvl::new(level.into()).unwrap());
let capacity = max_size let capacity = max_size

View file

@ -1,13 +1,11 @@
mod deflater; mod deflater;
use crate::AtomicMin;
use crate::{PngError, PngResult};
pub use deflater::crc32;
pub use deflater::deflate;
pub use deflater::inflate;
use std::{fmt, fmt::Display};
#[cfg(feature = "zopfli")] #[cfg(feature = "zopfli")]
use std::num::NonZeroU8; use std::num::NonZeroU8;
use std::{fmt, fmt::Display};
pub use deflater::{crc32, deflate, inflate};
use crate::{AtomicMin, PngError, PngResult};
#[cfg(feature = "zopfli")] #[cfg(feature = "zopfli")]
mod zopfli_oxipng; mod zopfli_oxipng;
#[cfg(feature = "zopfli")] #[cfg(feature = "zopfli")]

View file

@ -1,6 +1,7 @@
use crate::{PngError, PngResult};
use std::num::NonZeroU8; use std::num::NonZeroU8;
use crate::{PngError, PngResult};
pub fn deflate(data: &[u8], iterations: NonZeroU8) -> PngResult<Vec<u8>> { pub fn deflate(data: &[u8], iterations: NonZeroU8) -> PngResult<Vec<u8>> {
let mut output = Vec::with_capacity(data.len()); let mut output = Vec::with_capacity(data.len());
let options = zopfli::Options { let options = zopfli::Options {

View file

@ -1,6 +1,6 @@
use std::{error::Error, fmt};
use crate::colors::{BitDepth, ColorType}; use crate::colors::{BitDepth, ColorType};
use std::error::Error;
use std::fmt;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[non_exhaustive] #[non_exhaustive]

View file

@ -1,24 +1,22 @@
//! Check if a reduction makes file smaller, and keep best reductions. //! Check if a reduction makes file smaller, and keep best reductions.
//! Works asynchronously when possible //! Works asynchronously when possible
use crate::atomicmin::AtomicMin;
use crate::deflate;
use crate::filters::RowFilter;
use crate::png::PngImage;
#[cfg(not(feature = "parallel"))] #[cfg(not(feature = "parallel"))]
use crate::rayon; use std::cell::RefCell;
use crate::Deadline; use std::sync::{
use crate::PngError; atomic::{AtomicUsize, Ordering::*},
Arc,
};
#[cfg(feature = "parallel")] #[cfg(feature = "parallel")]
use crossbeam_channel::{unbounded, Receiver, Sender}; use crossbeam_channel::{unbounded, Receiver, Sender};
use indexmap::IndexSet; use indexmap::IndexSet;
use log::trace; use log::trace;
use rayon::prelude::*; use rayon::prelude::*;
#[cfg(not(feature = "parallel"))] #[cfg(not(feature = "parallel"))]
use std::cell::RefCell; use crate::rayon;
use std::sync::atomic::AtomicUsize; use crate::{atomicmin::AtomicMin, deflate, filters::RowFilter, png::PngImage, Deadline, PngError};
use std::sync::atomic::Ordering::*;
use std::sync::Arc;
pub struct Candidate { pub struct Candidate {
pub image: Arc<PngImage>, pub image: Arc<PngImage>,

View file

@ -1,5 +1,4 @@
use std::mem::transmute; use std::{fmt, fmt::Display, mem::transmute};
use std::{fmt, fmt::Display};
use crate::error::PngError; use crate::error::PngError;

View file

@ -1,14 +1,15 @@
use crate::colors::{BitDepth, ColorType};
use crate::deflate::{crc32, inflate};
use crate::error::PngError;
use crate::interlace::Interlacing;
use crate::AtomicMin;
use crate::Deflaters;
use crate::PngResult;
use indexmap::IndexSet; use indexmap::IndexSet;
use log::warn; use log::warn;
use rgb::{RGB16, RGBA8}; use rgb::{RGB16, RGBA8};
use crate::{
colors::{BitDepth, ColorType},
deflate::{crc32, inflate},
error::PngError,
interlace::Interlacing,
AtomicMin, Deflaters, PngResult,
};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Headers from the IHDR chunk of the image /// Headers from the IHDR chunk of the image
pub struct IhdrData { pub struct IhdrData {

View file

@ -1,10 +1,9 @@
use std::{fmt, fmt::Display}; use std::{fmt, fmt::Display};
use crate::headers::IhdrData;
use crate::png::PngImage;
use crate::PngError;
use bitvec::prelude::*; use bitvec::prelude::*;
use crate::{headers::IhdrData, png::PngImage, PngError};
#[repr(u8)] #[repr(u8)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Interlacing { pub enum Interlacing {

View file

@ -25,32 +25,40 @@ extern crate rayon;
#[cfg(not(feature = "parallel"))] #[cfg(not(feature = "parallel"))]
mod rayon; mod rayon;
use crate::atomicmin::AtomicMin; use std::{
use crate::evaluate::Evaluator; borrow::Cow,
use crate::headers::*; fs::{File, Metadata},
use crate::png::PngData; io::{stdin, stdout, BufWriter, Read, Write},
use crate::png::PngImage; path::Path,
use crate::reduction::*; sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::{Duration, Instant},
};
pub use indexmap::{indexset, IndexSet};
use log::{debug, info, trace, warn}; use log::{debug, info, trace, warn};
use rayon::prelude::*; use rayon::prelude::*;
use std::borrow::Cow;
use std::fs::{File, Metadata};
use std::io::{stdin, stdout, BufWriter, Read, Write};
use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant};
pub use crate::colors::{BitDepth, ColorType};
pub use crate::deflate::Deflaters;
pub use crate::error::PngError;
pub use crate::filters::RowFilter;
pub use crate::headers::StripChunks;
pub use crate::interlace::Interlacing;
pub use crate::options::{InFile, Options, OutFile};
pub use indexmap::{indexset, IndexSet};
pub use rgb::{RGB16, RGBA8}; pub use rgb::{RGB16, RGBA8};
use crate::{
atomicmin::AtomicMin,
evaluate::Evaluator,
headers::*,
png::{PngData, PngImage},
reduction::*,
};
pub use crate::{
colors::{BitDepth, ColorType},
deflate::Deflaters,
error::PngError,
filters::RowFilter,
headers::StripChunks,
interlace::Interlacing,
options::{InFile, Options, OutFile},
};
mod atomicmin; mod atomicmin;
mod colors; mod colors;
mod deflate; mod deflate;
@ -68,12 +76,9 @@ mod sanity_checks;
/// Private to oxipng; don't use outside tests and benches /// Private to oxipng; don't use outside tests and benches
#[doc(hidden)] #[doc(hidden)]
pub mod internal_tests { pub mod internal_tests {
pub use crate::atomicmin::*;
pub use crate::deflate::*;
pub use crate::png::*;
pub use crate::reduction::*;
#[cfg(feature = "sanity-checks")] #[cfg(feature = "sanity-checks")]
pub use crate::sanity_checks::*; pub use crate::sanity_checks::*;
pub use crate::{atomicmin::*, deflate::*, png::*, reduction::*};
} }
pub type PngResult<T> = Result<T, PngError>; pub type PngResult<T> = Result<T, PngError>;

View file

@ -16,23 +16,15 @@
#[cfg(not(feature = "parallel"))] #[cfg(not(feature = "parallel"))]
mod rayon; mod rayon;
#[cfg(feature = "zopfli")]
use std::num::NonZeroU8;
use std::{ffi::OsString, fs::DirBuilder, io::Write, path::PathBuf, process::exit, time::Duration};
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
use indexmap::IndexSet; use indexmap::IndexSet;
use log::{error, warn, Level, LevelFilter}; use log::{error, warn, Level, LevelFilter};
use oxipng::Deflaters; use oxipng::{Deflaters, InFile, Options, OutFile, RowFilter, StripChunks};
use oxipng::Options;
use oxipng::RowFilter;
use oxipng::StripChunks;
use oxipng::{InFile, OutFile};
use rayon::prelude::*; use rayon::prelude::*;
use std::ffi::OsString;
use std::fs::DirBuilder;
use std::io::Write;
#[cfg(feature = "zopfli")]
use std::num::NonZeroU8;
use std::path::PathBuf;
use std::process::exit;
use std::time::Duration;
fn main() { fn main() {
// Note: clap 'wrap_help' is enabled to automatically wrap lines according to terminal width. // Note: clap 'wrap_help' is enabled to automatically wrap lines according to terminal width.

View file

@ -1,13 +1,13 @@
use log::warn; use std::{
use std::fmt; fmt,
use std::path::{Path, PathBuf}; path::{Path, PathBuf},
use std::time::Duration; time::Duration,
};
use crate::deflate::Deflaters;
use crate::filters::RowFilter;
use crate::headers::StripChunks;
use crate::interlace::Interlacing;
use indexmap::{indexset, IndexSet}; use indexmap::{indexset, IndexSet};
use log::warn;
use crate::{deflate::Deflaters, filters::RowFilter, headers::StripChunks, interlace::Interlacing};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum OutFile { pub enum OutFile {

View file

@ -1,20 +1,25 @@
use crate::colors::{BitDepth, ColorType}; use std::{
use crate::deflate; fs::File,
use crate::error::PngError; io::{BufReader, Read, Write},
use crate::filters::*; path::Path,
use crate::headers::*; sync::Arc,
use crate::interlace::{deinterlace_image, interlace_image, Interlacing}; };
use crate::Options;
use bitvec::bitarr; use bitvec::bitarr;
use libdeflater::{CompressionLvl, Compressor}; use libdeflater::{CompressionLvl, Compressor};
use log::warn; use log::warn;
use rgb::ComponentSlice; use rgb::ComponentSlice;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::fs::File;
use std::io::{BufReader, Read, Write}; use crate::{
use std::iter::Iterator; colors::{BitDepth, ColorType},
use std::path::Path; deflate,
use std::sync::Arc; error::PngError,
filters::*,
headers::*,
interlace::{deinterlace_image, interlace_image, Interlacing},
Options,
};
pub(crate) mod scan_lines; pub(crate) mod scan_lines;

View file

@ -1,5 +1,4 @@
use crate::interlace::Interlacing; use crate::{interlace::Interlacing, png::PngImage};
use crate::png::PngImage;
/// An iterator over the scan lines of a PNG image /// An iterator over the scan lines of a PNG image
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View file

@ -1,8 +1,10 @@
use rgb::RGB16; use rgb::RGB16;
use crate::colors::{BitDepth, ColorType}; use crate::{
use crate::headers::IhdrData; colors::{BitDepth, ColorType},
use crate::png::PngImage; headers::IhdrData,
png::PngImage,
};
/// Clean the alpha channel by setting the color of all fully transparent pixels to black /// Clean the alpha channel by setting the color of all fully transparent pixels to black
pub fn cleaned_alpha_channel(png: &PngImage) -> Option<PngImage> { pub fn cleaned_alpha_channel(png: &PngImage) -> Option<PngImage> {

View file

@ -1,6 +1,8 @@
use crate::colors::{BitDepth, ColorType}; use crate::{
use crate::headers::IhdrData; colors::{BitDepth, ColorType},
use crate::png::PngImage; headers::IhdrData,
png::PngImage,
};
/// Attempt to reduce a 16-bit image to 8-bit, returning the reduced image if successful /// Attempt to reduce a 16-bit image to 8-bit, returning the reduced image if successful
#[must_use] #[must_use]

View file

@ -1,12 +1,15 @@
use crate::colors::{BitDepth, ColorType};
use crate::headers::IhdrData;
use crate::png::PngImage;
use indexmap::IndexSet;
use rgb::alt::Gray;
use rgb::{ComponentMap, ComponentSlice, FromSlice, RGB, RGBA};
use rustc_hash::FxHasher;
use std::hash::{BuildHasherDefault, Hash}; use std::hash::{BuildHasherDefault, Hash};
use indexmap::IndexSet;
use rgb::{alt::Gray, ComponentMap, ComponentSlice, FromSlice, RGB, RGBA};
use rustc_hash::FxHasher;
use crate::{
colors::{BitDepth, ColorType},
headers::IhdrData,
png::PngImage,
};
type FxIndexSet<V> = IndexSet<V, BuildHasherDefault<FxHasher>>; type FxIndexSet<V> = IndexSet<V, BuildHasherDefault<FxHasher>>;
/// Maximum size difference between indexed and channels to consider a candidate for evaluation /// Maximum size difference between indexed and channels to consider a candidate for evaluation

View file

@ -1,10 +1,7 @@
use crate::evaluate::Evaluator;
use crate::png::PngImage;
use crate::Deadline;
use crate::Deflaters;
use crate::Options;
use std::sync::Arc; use std::sync::Arc;
use crate::{evaluate::Evaluator, png::PngImage, Deadline, Deflaters, Options};
pub mod alpha; pub mod alpha;
use crate::alpha::*; use crate::alpha::*;
pub mod bit_depth; pub mod bit_depth;

View file

@ -1,11 +1,13 @@
use crate::colors::{BitDepth, ColorType};
use crate::headers::IhdrData;
use crate::png::scan_lines::ScanLine;
use crate::png::PngImage;
use crate::Interlacing;
use indexmap::IndexSet; use indexmap::IndexSet;
use rgb::RGBA8; use rgb::RGBA8;
use crate::{
colors::{BitDepth, ColorType},
headers::IhdrData,
png::{scan_lines::ScanLine, PngImage},
Interlacing,
};
/// Attempt to reduce the number of colors in the palette, returning the reduced image if successful /// Attempt to reduce the number of colors in the palette, returning the reduced image if successful
#[must_use] #[must_use]
pub fn reduced_palette(png: &PngImage, optimize_alpha: bool) -> Option<PngImage> { pub fn reduced_palette(png: &PngImage, optimize_alpha: bool) -> Option<PngImage> {

View file

@ -1,9 +1,9 @@
use indexmap::IndexSet; use std::{
use oxipng::internal_tests::*; fs::remove_file,
use oxipng::*; path::{Path, PathBuf},
use std::fs::remove_file; };
use std::path::Path;
use std::path::PathBuf; use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0; const GRAYSCALE: u8 = 0;
const RGB: u8 = 2; const RGB: u8 = 2;

View file

@ -1,15 +1,16 @@
use indexmap::{indexset, IndexSet};
use oxipng::internal_tests::*;
use oxipng::*;
#[cfg(feature = "filetime")] #[cfg(feature = "filetime")]
use std::cell::RefCell; use std::cell::RefCell;
use std::fs::remove_file;
#[cfg(feature = "zopfli")] #[cfg(feature = "zopfli")]
use std::num::NonZeroU8; use std::num::NonZeroU8;
#[cfg(feature = "filetime")] #[cfg(feature = "filetime")]
use std::ops::Deref; use std::ops::Deref;
use std::path::Path; use std::{
use std::path::PathBuf; fs::remove_file,
path::{Path, PathBuf},
};
use indexmap::indexset;
use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0; const GRAYSCALE: u8 = 0;
const RGB: u8 = 2; const RGB: u8 = 2;
@ -100,13 +101,14 @@ fn test_it_converts(
#[test] #[test]
fn verbose_mode() { fn verbose_mode() {
#[cfg(feature = "parallel")]
use crossbeam_channel::{unbounded, Sender};
use log::{set_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record};
use std::cell::RefCell; use std::cell::RefCell;
#[cfg(not(feature = "parallel"))] #[cfg(not(feature = "parallel"))]
use std::sync::mpsc::{channel as unbounded, Sender}; use std::sync::mpsc::{channel as unbounded, Sender};
#[cfg(feature = "parallel")]
use crossbeam_channel::{unbounded, Sender};
use log::{set_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record};
// Rust runs tests in parallel by default. // Rust runs tests in parallel by default.
// We want to make sure that we verify only logs from our test. // We want to make sure that we verify only logs from our test.
// //

View file

@ -1,9 +1,9 @@
use indexmap::IndexSet; use std::{
use oxipng::internal_tests::*; fs::remove_file,
use oxipng::*; path::{Path, PathBuf},
use std::fs::remove_file; };
use std::path::Path;
use std::path::PathBuf; use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0; const GRAYSCALE: u8 = 0;
const RGB: u8 = 2; const RGB: u8 = 2;

View file

@ -1,9 +1,9 @@
use indexmap::IndexSet; use std::{
use oxipng::internal_tests::*; fs::remove_file,
use oxipng::*; path::{Path, PathBuf},
use std::fs::remove_file; };
use std::path::Path;
use std::path::PathBuf; use oxipng::{internal_tests::*, *};
const RGB: u8 = 2; const RGB: u8 = 2;
const INDEXED: u8 = 3; const INDEXED: u8 = 3;

View file

@ -1,7 +1,6 @@
use std::{fs, fs::File, io::prelude::*};
use oxipng::*; use oxipng::*;
use std::fs;
use std::fs::File;
use std::io::prelude::*;
#[test] #[test]
fn optimize_from_memory() { fn optimize_from_memory() {

View file

@ -1,7 +1,6 @@
use oxipng::internal_tests::*; use std::{path::PathBuf, sync::Arc};
use oxipng::*;
use std::path::PathBuf; use oxipng::{internal_tests::*, *};
use std::sync::Arc;
fn get_opts() -> Options { fn get_opts() -> Options {
Options { Options {

View file

@ -1,9 +1,9 @@
use indexmap::IndexSet; use std::{
use oxipng::internal_tests::*; fs::remove_file,
use oxipng::*; path::{Path, PathBuf},
use std::fs::remove_file; };
use std::path::Path;
use std::path::PathBuf; use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0; const GRAYSCALE: u8 = 0;
const RGB: u8 = 2; const RGB: u8 = 2;

View file

@ -1,10 +1,10 @@
use indexmap::IndexSet; use std::{
use oxipng::internal_tests::*; fs::remove_file,
use oxipng::*; path::{Path, PathBuf},
use std::fs::remove_file; sync::Arc,
use std::path::Path; };
use std::path::PathBuf;
use std::sync::Arc; use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0; const GRAYSCALE: u8 = 0;
const RGB: u8 = 2; const RGB: u8 = 2;

View file

@ -1,9 +1,9 @@
use indexmap::IndexSet; use std::{
use oxipng::internal_tests::*; fs::remove_file,
use oxipng::*; path::{Path, PathBuf},
use std::fs::remove_file; };
use std::path::Path;
use std::path::PathBuf; use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0; const GRAYSCALE: u8 = 0;
const RGB: u8 = 2; const RGB: u8 = 2;