async_compression_issue_150_workaround/
lib.rs1# | [`futures::io::AsyncBufRead`](futures_io::AsyncBufRead), [`futures::io::AsyncWrite`](futures_io::AsyncWrite)"
35)]
36#![cfg_attr(
37 not(feature = "futures-io"),
38 doc = "`futures-io` (*inactive*) | `futures::io::AsyncBufRead`, `futures::io::AsyncWrite`"
39)]
40#![cfg_attr(
41 feature = "futures-bufread",
42 doc = "`futures-bufread` | (*deprecated*, use `futures-io`)"
43)]
44#![cfg_attr(
45 feature = "futures-write",
46 doc = "`futures-write` | (*deprecated*, use `futures-io`)"
47)]
48#![cfg_attr(
49 feature = "stream",
50 doc = "[`stream`] | (*deprecated*, see [`async-compression:stream`](crate::stream) docs for migration)"
51)]
52#![cfg_attr(
53 not(feature = "stream"),
54 doc = "`stream` (*inactive*) | (*deprecated*, see `async-compression::stream` docs for migration)"
55)]
56# | [`tokio::io::AsyncBufRead`](::tokio_02::io::AsyncBufRead), [`tokio::io::AsyncWrite`](::tokio_02::io::AsyncWrite)"
59)]
60#![cfg_attr(
61 not(feature = "tokio-02"),
62 doc = "`tokio-02` (*inactive*) | `tokio::io::AsyncBufRead`, `tokio::io::AsyncWrite`"
63)]
64# | [`tokio::io::AsyncBufRead`](::tokio_03::io::AsyncBufRead), [`tokio::io::AsyncWrite`](::tokio_03::io::AsyncWrite)"
67)]
68#![cfg_attr(
69 not(feature = "tokio-03"),
70 doc = "`tokio-03` (*inactive*) | `tokio::io::AsyncBufRead`, `tokio::io::AsyncWrite`"
71)]
72# | [`tokio::io::AsyncBufRead`](::tokio::io::AsyncBufRead), [`tokio::io::AsyncWrite`](::tokio::io::AsyncWrite)"
75)]
76#![cfg_attr(
77 not(feature = "tokio"),
78 doc = "`tokio` (*inactive*) | `tokio::io::AsyncBufRead`, `tokio::io::AsyncWrite`"
79)]
80#, [`BrotliDecoder`](?search=BrotliDecoder)"
93)]
94#![cfg_attr(
95 not(feature = "brotli"),
96 doc = "`brotli` (*inactive*) | `BrotliEncoder`, `BrotliDecoder`"
97)]
98#, [`BzDecoder`](?search=BzDecoder)"
101)]
102#![cfg_attr(
103 not(feature = "bzip2"),
104 doc = "`bzip2` (*inactive*) | `BzEncoder`, `BzDecoder`"
105)]
106#, [`DeflateDecoder`](?search=DeflateDecoder)"
109)]
110#![cfg_attr(
111 not(feature = "deflate"),
112 doc = "`deflate` (*inactive*) | `DeflateEncoder`, `DeflateDecoder`"
113)]
114#, [`GzipDecoder`](?search=GzipDecoder)"
117)]
118#![cfg_attr(
119 not(feature = "gzip"),
120 doc = "`gzip` (*inactive*) | `GzipEncoder`, `GzipDecoder`"
121)]
122#, [`LzmaDecoder`](?search=LzmaDecoder)"
125)]
126#![cfg_attr(
127 not(feature = "lzma"),
128 doc = "`lzma` (*inactive*) | `LzmaEncoder`, `LzmaDecoder`"
129)]
130#, [`XzDecoder`](?search=XzDecoder)"
133)]
134#![cfg_attr(
135 not(feature = "xz"),
136 doc = "`xz` (*inactive*) | `XzEncoder`, `XzDecoder`"
137)]
138#, [`ZlibDecoder`](?search=ZlibDecoder)"
141)]
142#![cfg_attr(
143 not(feature = "zlib"),
144 doc = "`zlib` (*inactive*) | `ZlibEncoder`, `ZlibDecoder`"
145)]
146#, [`ZstdDecoder`](?search=ZstdDecoder)"
149)]
150#![cfg_attr(
151 not(feature = "zstd"),
152 doc = "`zstd` (*inactive*) | `ZstdEncoder`, `ZstdDecoder`"
153)]
154#![cfg_attr(docsrs, feature(doc_cfg))]
157#![warn(rust_2018_idioms)]
158#![cfg_attr(not(all), allow(unused))]
159
160#[macro_use]
161mod macros;
162pub mod codec;
163
164#[cfg(feature = "futures-io")]
165#[cfg_attr(docsrs, doc(cfg(feature = "futures-io")))]
166pub mod futures;
167#[cfg(feature = "stream")]
168#[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
169pub mod stream;
170#[cfg(feature = "tokio")]
171#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
172pub mod tokio;
173#[cfg(feature = "tokio-02")]
174#[cfg_attr(docsrs, doc(cfg(feature = "tokio-02")))]
175pub mod tokio_02;
176#[cfg(feature = "tokio-03")]
177#[cfg_attr(docsrs, doc(cfg(feature = "tokio-03")))]
178pub mod tokio_03;
179
180mod unshared;
181pub mod util;
182
183#[cfg(feature = "brotli")]
184use brotli::enc::backward_references::BrotliEncoderParams;
185
186#[non_exhaustive]
188#[derive(Clone, Copy, Debug)]
189pub enum Level {
190 Fastest,
192 Best,
194 Default,
196 Precise(u32),
201}
202
203impl Level {
204 #[cfg(feature = "brotli")]
205 fn into_brotli(self, mut params: BrotliEncoderParams) -> BrotliEncoderParams {
206 match self {
207 Self::Fastest => params.quality = 0,
208 Self::Best => params.quality = 11,
209 Self::Precise(quality) => params.quality = quality.min(11) as i32,
210 Self::Default => (),
211 }
212
213 params
214 }
215
216 #[cfg(feature = "bzip2")]
217 fn into_bzip2(self) -> bzip2::Compression {
218 match self {
219 Self::Fastest => bzip2::Compression::fast(),
220 Self::Best => bzip2::Compression::best(),
221 Self::Precise(quality) => bzip2::Compression::new(quality.max(1).min(9)),
222 Self::Default => bzip2::Compression::default(),
223 }
224 }
225
226 #[cfg(feature = "flate2")]
227 fn into_flate2(self) -> flate2::Compression {
228 match self {
229 Self::Fastest => flate2::Compression::fast(),
230 Self::Best => flate2::Compression::best(),
231 Self::Precise(quality) => flate2::Compression::new(quality.min(10)),
232 Self::Default => flate2::Compression::default(),
233 }
234 }
235
236 #[cfg(feature = "zstd")]
237 fn into_zstd(self) -> i32 {
238 match self {
239 Self::Fastest => 1,
240 Self::Best => 21,
241 Self::Precise(quality) => quality.min(21) as i32,
242 Self::Default => 0,
243 }
244 }
245
246 #[cfg(feature = "xz2")]
247 fn into_xz2(self) -> u32 {
248 match self {
249 Self::Fastest => 0,
250 Self::Best => 9,
251 Self::Precise(quality) => quality.min(9),
252 Self::Default => 5,
253 }
254 }
255}