Skip to content

Commit 0e2d166

Browse files
authored
Merge pull request #234 from Nullus157/new/feat
Add new feature `zstdmt` for `zstd::CParameter::nb_workers`
2 parents b465a48 + 4e1dc95 commit 0e2d166

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0),
66

77
## Unreleased
88

9+
- Add `zstdmt` crate feature that enables `zstd-safe/zstdmt`, allowing multi-threaded functionality to work as expected.
10+
911
## 0.4.0 - 2023-05-10
1012

1113
- `Level::Precise` variant now takes a `i32` instead of `u32`.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ lzma = ["xz2"]
2828
xz = ["xz2"]
2929
zlib = ["flate2"]
3030
zstd = ["libzstd", "zstd-safe"]
31+
zstdmt = ["zstd", "zstd-safe/zstdmt"]
3132

3233
[dependencies]
3334
brotli = { version = "3.3", optional = true, default-features = false, features = ["std"] }

src/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
)]
122122
//!
123123
124-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
124+
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
125125
#![warn(
126126
missing_docs,
127127
rust_2018_idioms,
@@ -326,6 +326,14 @@ pub mod zstd {
326326
///
327327
/// If set to 0, compression functions will block; if set to 1 or more, compression will
328328
/// run in background threads and `flush` pushes bytes through the compressor.
329+
///
330+
/// # Panics
331+
///
332+
/// This parameter requires feature `zstdmt` to be enabled, otherwise it will cause a panic
333+
/// when used in `ZstdEncoder::with_quality_and_params()` calls.
334+
//
335+
// TODO: make this a normal feature guarded fn on next breaking release
336+
#[cfg_attr(docsrs, doc(cfg(feature = "zstdmt")))]
329337
pub fn nb_workers(value: u32) -> Self {
330338
Self(NbWorkers(value))
331339
}

src/macros.rs

+10
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ macro_rules! algos {
8888

8989
/// Creates a new encoder, using the specified compression level and parameters, which
9090
/// will read uncompressed data from the given stream and emit a compressed stream.
91+
///
92+
/// # Panics
93+
///
94+
/// Panics if this function is called with a [`CParameter::nb_workers()`] parameter and
95+
/// the `zstdmt` crate feature is _not_ enabled.
96+
///
97+
/// [`CParameter::nb_workers()`]: crate::zstd::CParameter
98+
//
99+
// TODO: remove panic note on next breaking release, along with `CParameter::nb_workers`
100+
// change
91101
pub fn with_quality_and_params(inner: $inner, level: crate::Level, params: &[crate::zstd::CParameter]) -> Self {
92102
Self {
93103
inner: crate::$($mod::)+generic::Encoder::new(

0 commit comments

Comments
 (0)