Skip to content

Commit

Permalink
chroe: cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Jul 10, 2023
1 parent 3ee4609 commit 5802262
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
21 changes: 14 additions & 7 deletions crates/compression/src/encoder.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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<usize> {
impl Write for Writer {
fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
self.buf.extend_from_slice(buf);
Ok(buf.len())
}

fn flush(&mut self) -> io::Result<()> {
fn flush(&mut self) -> IoResult<()> {
Ok(())
}
}
Expand Down Expand Up @@ -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")]
Expand All @@ -111,7 +117,7 @@ impl Encoder {
}
}
#[inline]
pub(super) fn take(&mut self) -> Result<Bytes, IoError> {
pub(super) fn take(&mut self) -> IoResult<Bytes> {
match *self {
#[cfg(feature = "brotli")]
Self::Brotli(ref mut encoder) => {
Expand All @@ -136,7 +142,7 @@ impl Encoder {
}
}

pub(super) fn finish(self) -> Result<Bytes, IoError> {
pub(super) fn finish(self) -> IoResult<Bytes> {
match self {
#[cfg(feature = "brotli")]
Self::Brotli(mut encoder) => match encoder.flush() {
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions crates/compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion crates/compression/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ pub(super) struct EncodeStream<B> {
}

impl<B> EncodeStream<B> {
#[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)),
}
}
}
Expand Down

0 comments on commit 5802262

Please sign in to comment.