Skip to content

Commit

Permalink
Fix some new nightly Clippy lints and run rustfmt with prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTMjugador committed Feb 20, 2024
1 parent 98fd4de commit 0608ab9
Show file tree
Hide file tree
Showing 35 changed files with 191 additions and 189 deletions.
4 changes: 2 additions & 2 deletions benches/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions benches/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions benches/interlacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions benches/reductions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions benches/strategies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions benches/zopfli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/atomicmin.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/colors.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions src/deflate/deflater.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/deflate/mod.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
3 changes: 2 additions & 1 deletion src/deflate/zopfli_oxipng.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
20 changes: 9 additions & 11 deletions src/evaluate.rs
Original file line number Diff line number Diff line change
@@ -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>,
Expand Down
3 changes: 1 addition & 2 deletions src/filters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::mem::transmute;
use std::{fmt, fmt::Display};
use std::{fmt, fmt::Display, mem::transmute};

use crate::error::PngError;

Expand Down
15 changes: 8 additions & 7 deletions src/headers.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/interlace.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
57 changes: 31 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>;
Expand Down
18 changes: 5 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use log::warn;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::Duration;

use crate::deflate::Deflaters;
use crate::filters::RowFilter;
use crate::headers::StripChunks;
use crate::interlace::Interlacing;
use std::{
fmt,
path::{Path, PathBuf},
time::Duration,
};

use indexmap::{indexset, IndexSet};
use log::warn;

use crate::{deflate::Deflaters, filters::RowFilter, headers::StripChunks, interlace::Interlacing};

#[derive(Clone, Debug)]
pub enum OutFile {
Expand Down
29 changes: 17 additions & 12 deletions src/png/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/png/scan_lines.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
Loading

0 comments on commit 0608ab9

Please sign in to comment.