Skip to content

Commit

Permalink
♻️ Use [lints] in Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
inflation committed Nov 16, 2023
1 parent 59a7cf1 commit ff1bc74
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["jpegxl-src", "jpegxl-sys", "jpegxl-rs"]
resolver = "2"
resolver = "2"
6 changes: 6 additions & 0 deletions jpegxl-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ version = "0.8.3+libjxl-0.8.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints.rust]
missing_docs = "warn"

[lints.clippy]
pedantic = "warn"

[features]
default = ["image", "threads"]
image = ["dep:image"]
Expand Down
11 changes: 7 additions & 4 deletions jpegxl-rs/benches/decode.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![allow(missing_docs)]
#![allow(clippy::missing_panics_doc)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use jpegxl_rs::*;
use jpegxl_rs::{decoder_builder, parallel, ResizableRunner};
use parallel::threads_runner::ThreadsRunner;

const SAMPLE: &[u8] = include_bytes!("../../samples/bench.jxl");
Expand All @@ -10,7 +13,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {

let decoder = decoder_builder().build().unwrap();
group.bench_function("single thread", |b| {
b.iter_with_large_drop(|| decoder.decode_with::<u8>(black_box(SAMPLE)).unwrap())
b.iter_with_large_drop(|| decoder.decode_with::<u8>(black_box(SAMPLE)).unwrap());
});

let parallel_runner = ThreadsRunner::default();
Expand All @@ -19,7 +22,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
.build()
.unwrap();
group.bench_function("thread pool using default number of threads", |b| {
b.iter_with_large_drop(|| decoder.decode_with::<u8>(black_box(SAMPLE)).unwrap())
b.iter_with_large_drop(|| decoder.decode_with::<u8>(black_box(SAMPLE)).unwrap());
});

let parallel_runner = ResizableRunner::default();
Expand All @@ -28,7 +31,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
.build()
.unwrap();
group.bench_function("resizable thread pool", |b| {
b.iter_with_large_drop(|| decoder.decode_with::<u8>(black_box(SAMPLE)).unwrap())
b.iter_with_large_drop(|| decoder.decode_with::<u8>(black_box(SAMPLE)).unwrap());
});

group.finish();
Expand Down
9 changes: 6 additions & 3 deletions jpegxl-rs/benches/encode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(missing_docs)]
#![allow(clippy::missing_panics_doc)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use jpegxl_rs::{encoder_builder, ResizableRunner, ThreadsRunner};

Expand All @@ -16,7 +19,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
encoder
.encode::<_, u8>(black_box(sample.as_raw()), sample.width(), sample.height())
.unwrap()
})
});
});

let parallel_runner = ThreadsRunner::default();
Expand All @@ -29,7 +32,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
encoder
.encode::<_, u8>(black_box(sample.as_raw()), sample.width(), sample.height())
.unwrap()
})
});
});

let parallel_runner = ResizableRunner::default();
Expand All @@ -42,7 +45,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
encoder
.encode::<_, u8>(black_box(sample.as_raw()), sample.width(), sample.height())
.unwrap()
})
});
});

group.finish();
Expand Down
32 changes: 16 additions & 16 deletions jpegxl-rs/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ impl<'pr, 'mm> JxlDecoder<'pr, 'mm> {

let mut status;
loop {
use JxlDecoderStatus::*;
use JxlDecoderStatus as s;

status = unsafe { JxlDecoderProcessInput(self.dec) };

match status {
NeedMoreInput | Error => return Err(DecodeError::GenericError),
s::NeedMoreInput | s::Error => return Err(DecodeError::GenericError),

// Get the basic info
BasicInfo => {
s::BasicInfo => {
check_dec_status(unsafe {
JxlDecoderGetBasicInfo(self.dec, basic_info.as_mut_ptr())
})?;
Expand All @@ -238,12 +238,12 @@ impl<'pr, 'mm> JxlDecoder<'pr, 'mm> {
}

// Get color encoding
ColorEncoding => {
s::ColorEncoding => {
self.get_icc_profile(unsafe { icc.as_mut().unwrap_unchecked() })?;
}

// Get JPEG reconstruction buffer
JpegReconstruction => {
s::JpegReconstruction => {
// Safety: JpegReconstruction is only called when reconstruct_jpeg_buffer
// is not None
let buf = unsafe { reconstruct_jpeg_buffer.as_mut().unwrap_unchecked() };
Expand All @@ -254,7 +254,7 @@ impl<'pr, 'mm> JxlDecoder<'pr, 'mm> {
}

// JPEG buffer need more space
JpegNeedMoreOutput => {
s::JpegNeedMoreOutput => {
// Safety: JpegNeedMoreOutput is only called when reconstruct_jpeg_buffer
// is not None
let buf = unsafe { reconstruct_jpeg_buffer.as_mut().unwrap_unchecked() };
Expand All @@ -267,12 +267,12 @@ impl<'pr, 'mm> JxlDecoder<'pr, 'mm> {
}

// Get the output buffer
NeedImageOutBuffer => {
s::NeedImageOutBuffer => {
self.output(unsafe { &*basic_info.as_ptr() }, data_type, format, pixels)?;
}

FullImage => continue,
Success => {
s::FullImage => continue,
s::Success => {
if let Some(buf) = reconstruct_jpeg_buffer.as_mut() {
let remaining = unsafe { JxlDecoderReleaseJPEGBuffer(self.dec) };

Expand All @@ -296,13 +296,13 @@ impl<'pr, 'mm> JxlDecoder<'pr, 'mm> {
icc_profile: icc,
});
}
NeedPreviewOutBuffer => todo!(),
BoxNeedMoreOutput => todo!(),
Extensions => todo!(),
PreviewImage => todo!(),
Frame => todo!(),
Box => todo!(),
FrameProgression => todo!(),
s::NeedPreviewOutBuffer => todo!(),
s::BoxNeedMoreOutput => todo!(),
s::Extensions => todo!(),
s::PreviewImage => todo!(),
s::Frame => todo!(),
s::Box => todo!(),
s::FrameProgression => todo!(),
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions jpegxl-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ You should have received a copy of the GNU General Public License
along with jpegxl-rs. If not, see <https://www.gnu.org/licenses/>.
*/

#![warn(missing_docs)]
#![deny(clippy::all)]
#![warn(clippy::pedantic)]
#![allow(clippy::enum_glob_use)]

//! [![Documentation](https://docs.rs/jpegxl-rs/badge.svg)](https://docs.rs/jpegxl-rs/)
//! [![Crates.io](https://img.shields.io/crates/v/jpegxl-rs.svg)](https://crates.io/crates/jpegxl-rs)
//! [![dependency status](https://deps.rs/repo/github/inflation/jpegxl-rs/status.svg)](https://deps.rs/repo/github/inflation/jpegxl-rs)
Expand Down
4 changes: 4 additions & 0 deletions jpegxl-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ version = "0.8.2+libjxl-0.8.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints.clippy]
pedantic = "warn"
module_name_repetitions = "allow"

[package.metadata.docs.rs]
features = ["docs"]

Expand Down
8 changes: 4 additions & 4 deletions jpegxl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ fn main() {
.unwrap();

if let Ok(path) = env::var("DEP_JXL_LIB") {
println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-search=native={path}");
println!("cargo:rustc-link-lib=jxl");
#[cfg(feature = "threads")]
println!("cargo:rustc-link-lib=jxl_threads");
} else {
pkg_config::Config::new()
.atleast_version(version)
.probe("libjxl")
.unwrap_or_else(|_| panic!("Cannot find `libjxl` with version >= {}", version));
.unwrap_or_else(|_| panic!("Cannot find `libjxl` with version >= {version}"));
#[cfg(feature = "threads")]
pkg_config::Config::new()
.atleast_version(version)
.probe("libjxl_threads")
.unwrap_or_else(|_| {
panic!("Cannot find `libjxl_threads` with version >= {}", version)
panic!("Cannot find `libjxl_threads` with version >= {version}")
});
}
}

#[cfg(feature = "vendored")]
jpegxl_src::build()
jpegxl_src::build();
}
2 changes: 0 additions & 2 deletions jpegxl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see <https://www.gnu.org/licenses/>.
*/

#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

pub mod butteraugli;
Expand Down

0 comments on commit ff1bc74

Please sign in to comment.