diff --git a/crates/compression/src/encoder.rs b/crates/compression/src/encoder.rs index 170a0001d..f45566c80 100644 --- a/crates/compression/src/encoder.rs +++ b/crates/compression/src/encoder.rs @@ -1,9 +1,12 @@ //! Compress the body of a response. -use std::io::{self, Error as IoError, Write}; +use std::io::{Result as IoResult, Write}; +#[cfg(feature = "brotli")] use brotli::CompressorWriter as BrotliEncoder; use bytes::{Bytes, BytesMut}; +#[cfg(feature = "gzip")] use flate2::write::{GzEncoder, ZlibEncoder}; +#[cfg(feature = "zstd")] use zstd::stream::write::Encoder as ZstdEncoder; use super::{CompressionAlgo, CompressionLevel}; @@ -13,24 +16,26 @@ pub(super) struct Writer { } impl Writer { + #[allow(dead_code)] fn new() -> Writer { Writer { buf: BytesMut::with_capacity(8192), } } + #[allow(dead_code)] fn take(&mut self) -> Bytes { self.buf.split().freeze() } } -impl io::Write for Writer { - fn write(&mut self, buf: &[u8]) -> io::Result { +impl Write for Writer { + fn write(&mut self, buf: &[u8]) -> IoResult { self.buf.extend_from_slice(buf); Ok(buf.len()) } - fn flush(&mut self) -> io::Result<()> { + fn flush(&mut self) -> IoResult<()> { Ok(()) } } @@ -98,6 +103,7 @@ pub(super) enum Encoder { } impl Encoder { + #[allow(unused_variables)] pub(super) fn new(algo: CompressionAlgo, level: CompressionLevel) -> Self { match algo { #[cfg(feature = "brotli")] @@ -111,7 +117,7 @@ impl Encoder { } } #[inline] - pub(super) fn take(&mut self) -> Result { + pub(super) fn take(&mut self) -> IoResult { match *self { #[cfg(feature = "brotli")] Self::Brotli(ref mut encoder) => { @@ -136,7 +142,7 @@ impl Encoder { } } - pub(super) fn finish(self) -> Result { + pub(super) fn finish(self) -> IoResult { match self { #[cfg(feature = "brotli")] Self::Brotli(mut encoder) => match encoder.flush() { @@ -161,7 +167,8 @@ impl Encoder { } } - pub(super) fn write(&mut self, data: &[u8]) -> Result<(), IoError> { + #[allow(unused_variables)] + pub(super) fn write(&mut self, data: &[u8]) -> IoResult<()> { match *self { #[cfg(feature = "brotli")] Self::Brotli(ref mut encoder) => encoder.write_all(data), diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index 9377f4158..61d2cbebd 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -109,6 +109,7 @@ pub struct Compression { impl Default for Compression { #[inline] fn default() -> Self { + #[allow(unused_mut)] let mut algos = IndexMap::new(); #[cfg(feature = "zstd")] algos.insert(CompressionAlgo::Zstd, CompressionLevel::Default); diff --git a/crates/compression/src/stream.rs b/crates/compression/src/stream.rs index 6698466aa..80677abd8 100644 --- a/crates/compression/src/stream.rs +++ b/crates/compression/src/stream.rs @@ -25,12 +25,13 @@ pub(super) struct EncodeStream { } impl EncodeStream { + #[allow(unused_variables)] pub(super) fn new(algo: CompressionAlgo, level: CompressionLevel, body: B) -> Self { Self { - encoder: Some(Encoder::new(algo, level)), body, eof: false, encoding: None, + encoder: Some(Encoder::new(algo, level)), } } }