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 test;
use oxipng::internal_tests::*;
use oxipng::*;
use std::path::PathBuf;
use oxipng::{internal_tests::*, *};
use test::Bencher;
#[bench]

View file

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

View file

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

View file

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

View file

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

View file

@ -3,10 +3,9 @@
extern crate oxipng;
extern crate test;
use oxipng::internal_tests::*;
use oxipng::*;
use std::num::NonZeroU8;
use std::path::PathBuf;
use std::{num::NonZeroU8, path::PathBuf};
use oxipng::{internal_tests::*, *};
use test::Bencher;
// 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::Ordering::SeqCst;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
#[derive(Debug)]
pub struct AtomicMin {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,4 @@
use std::mem::transmute;
use std::{fmt, fmt::Display};
use std::{fmt, fmt::Display, mem::transmute};
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 log::warn;
use rgb::{RGB16, RGBA8};
use crate::{
colors::{BitDepth, ColorType},
deflate::{crc32, inflate},
error::PngError,
interlace::Interlacing,
AtomicMin, Deflaters, PngResult,
};
#[derive(Debug, Clone)]
/// Headers from the IHDR chunk of the image
pub struct IhdrData {

View file

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

View file

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

View file

@ -16,23 +16,15 @@
#[cfg(not(feature = "parallel"))]
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 indexmap::IndexSet;
use log::{error, warn, Level, LevelFilter};
use oxipng::Deflaters;
use oxipng::Options;
use oxipng::RowFilter;
use oxipng::StripChunks;
use oxipng::{InFile, OutFile};
use oxipng::{Deflaters, InFile, Options, OutFile, RowFilter, StripChunks};
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() {
// 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::fmt;
use std::path::{Path, PathBuf};
use std::time::Duration;
use std::{
fmt,
path::{Path, PathBuf},
time::Duration,
};
use crate::deflate::Deflaters;
use crate::filters::RowFilter;
use crate::headers::StripChunks;
use crate::interlace::Interlacing;
use indexmap::{indexset, IndexSet};
use log::warn;
use crate::{deflate::Deflaters, filters::RowFilter, headers::StripChunks, interlace::Interlacing};
#[derive(Clone, Debug)]
pub enum OutFile {

View file

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

View file

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

View file

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

View file

@ -1,6 +1,8 @@
use crate::colors::{BitDepth, ColorType};
use crate::headers::IhdrData;
use crate::png::PngImage;
use crate::{
colors::{BitDepth, ColorType},
headers::IhdrData,
png::PngImage,
};
/// Attempt to reduce a 16-bit image to 8-bit, returning the reduced image if successful
#[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 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>>;
/// 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 crate::{evaluate::Evaluator, png::PngImage, Deadline, Deflaters, Options};
pub mod alpha;
use crate::alpha::*;
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 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
#[must_use]
pub fn reduced_palette(png: &PngImage, optimize_alpha: bool) -> Option<PngImage> {

View file

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

View file

@ -1,15 +1,16 @@
use indexmap::{indexset, IndexSet};
use oxipng::internal_tests::*;
use oxipng::*;
#[cfg(feature = "filetime")]
use std::cell::RefCell;
use std::fs::remove_file;
#[cfg(feature = "zopfli")]
use std::num::NonZeroU8;
#[cfg(feature = "filetime")]
use std::ops::Deref;
use std::path::Path;
use std::path::PathBuf;
use std::{
fs::remove_file,
path::{Path, PathBuf},
};
use indexmap::indexset;
use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
@ -100,13 +101,14 @@ fn test_it_converts(
#[test]
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;
#[cfg(not(feature = "parallel"))]
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.
// We want to make sure that we verify only logs from our test.
//

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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