Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clippy happy + a few more cleanups #285

Merged
merged 5 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Crc {
}

impl<R: Read> CrcReader<R> {
/// Create a new CrcReader.
/// Create a new `CrcReader`.
pub fn new(r: R) -> CrcReader<R> {
CrcReader {
inner: r,
Expand All @@ -79,27 +79,27 @@ impl<R: Read> CrcReader<R> {
}

impl<R> CrcReader<R> {
/// Get the Crc for this CrcReader.
/// Get the Crc for this `CrcReader`.
pub fn crc(&self) -> &Crc {
&self.crc
}

/// Get the reader that is wrapped by this CrcReader.
/// Get the reader that is wrapped by this `CrcReader`.
pub fn into_inner(self) -> R {
self.inner
}

/// Get the reader that is wrapped by this CrcReader by reference.
/// Get the reader that is wrapped by this `CrcReader` by reference.
pub fn get_ref(&self) -> &R {
&self.inner
}

/// Get a mutable reference to the reader that is wrapped by this CrcReader.
/// Get a mutable reference to the reader that is wrapped by this `CrcReader`.
pub fn get_mut(&mut self) -> &mut R {
&mut self.inner
}

/// Reset the Crc in this CrcReader.
/// Reset the Crc in this `CrcReader`.
pub fn reset(&mut self) {
self.crc.reset();
}
Expand Down Expand Up @@ -135,34 +135,34 @@ pub struct CrcWriter<W> {
}

impl<W> CrcWriter<W> {
/// Get the Crc for this CrcWriter.
/// Get the Crc for this `CrcWriter`.
pub fn crc(&self) -> &Crc {
&self.crc
}

/// Get the writer that is wrapped by this CrcWriter.
/// Get the writer that is wrapped by this `CrcWriter`.
pub fn into_inner(self) -> W {
self.inner
}

/// Get the writer that is wrapped by this CrcWriter by reference.
/// Get the writer that is wrapped by this `CrcWriter` by reference.
pub fn get_ref(&self) -> &W {
&self.inner
}

/// Get a mutable reference to the writer that is wrapped by this CrcWriter.
/// Get a mutable reference to the writer that is wrapped by this `CrcWriter`.
pub fn get_mut(&mut self) -> &mut W {
&mut self.inner
}

/// Reset the Crc in this CrcWriter.
/// Reset the Crc in this `CrcWriter`.
pub fn reset(&mut self) {
self.crc.reset();
}
}

impl<W: Write> CrcWriter<W> {
/// Create a new CrcWriter.
/// Create a new `CrcWriter`.
pub fn new(w: W) -> CrcWriter<W> {
CrcWriter {
inner: w,
Expand Down
16 changes: 8 additions & 8 deletions src/deflate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ mod tests {
let v = crate::random_bytes().take(1024).collect::<Vec<_>>();
for _ in 0..200 {
let to_write = &v[..thread_rng().gen_range(0..v.len())];
real.extend(to_write.iter().map(|x| *x));
real.extend(to_write.iter().copied());
w.write_all(to_write).unwrap();
}
let result = w.finish().unwrap();
let mut r = read::DeflateDecoder::new(&result[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == real);
assert_eq!(ret, real);
}

#[test]
Expand All @@ -37,7 +37,7 @@ mod tests {
let mut r = read::DeflateDecoder::new(&data[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == b"foo");
assert_eq!(ret, b"foo");
}

#[test]
Expand All @@ -47,21 +47,21 @@ mod tests {
let v = crate::random_bytes().take(1024).collect::<Vec<_>>();
for _ in 0..200 {
let to_write = &v[..thread_rng().gen_range(0..v.len())];
real.extend(to_write.iter().map(|x| *x));
real.extend(to_write.iter().copied());
w.write_all(to_write).unwrap();
}
let mut result = w.finish().unwrap();

let result_len = result.len();

for _ in 0..200 {
result.extend(v.iter().map(|x| *x));
result.extend(v.iter().copied());
}

let mut r = read::DeflateDecoder::new(&result[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == real);
assert_eq!(ret, real);
assert_eq!(r.total_in(), result_len as u64);
}

Expand All @@ -84,7 +84,7 @@ mod tests {
);
w.write_all(&v).unwrap();
let w = w.finish().unwrap().finish().unwrap();
assert!(w == v);
assert_eq!(w, v);
}

#[test]
Expand Down Expand Up @@ -159,7 +159,7 @@ mod tests {

let mut d = read::DeflateDecoder::new(&result[..]);
let mut data = Vec::new();
assert!(d.read(&mut data).unwrap() == 0);
assert_eq!(d.read(&mut data).unwrap(), 0);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/ffi/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ impl InflateBackend for Inflate {
let raw = &mut *self.inner.stream_wrapper;
raw.msg = ptr::null_mut();
raw.next_in = input.as_ptr() as *mut u8;
raw.avail_in = cmp::min(input.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_in = cmp::min(input.len(), c_uint::MAX as usize) as c_uint;
raw.next_out = output.as_mut_ptr();
raw.avail_out = cmp::min(output.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_out = cmp::min(output.len(), c_uint::MAX as usize) as c_uint;

let rc = unsafe { mz_inflate(raw, flush as c_int) };

Expand Down Expand Up @@ -303,9 +303,9 @@ impl DeflateBackend for Deflate {
let raw = &mut *self.inner.stream_wrapper;
raw.msg = ptr::null_mut();
raw.next_in = input.as_ptr() as *mut _;
raw.avail_in = cmp::min(input.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_in = cmp::min(input.len(), c_uint::MAX as usize) as c_uint;
raw.next_out = output.as_mut_ptr();
raw.avail_out = cmp::min(output.len(), c_uint::max_value() as usize) as c_uint;
raw.avail_out = cmp::min(output.len(), c_uint::MAX as usize) as c_uint;

let rc = unsafe { mz_deflate(raw, flush as c_int) };

Expand Down
2 changes: 1 addition & 1 deletion src/ffi/rust.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Implementation for miniz_oxide rust backend.
//! Implementation for `miniz_oxide` rust backend.

use std::convert::TryInto;
use std::fmt;
Expand Down
14 changes: 7 additions & 7 deletions src/gz/bufread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn read_gz_header_part<'a, R: Read>(r: &'a mut Buffer<'a, R>) -> io::Result<()>
}
GzHeaderParsingState::Filename => {
if r.part.flg & FNAME != 0 {
if None == r.part.header.filename {
if r.part.header.filename.is_none() {
r.part.header.filename = Some(Vec::new());
};
for byte in r.bytes() {
Expand All @@ -88,7 +88,7 @@ fn read_gz_header_part<'a, R: Read>(r: &'a mut Buffer<'a, R>) -> io::Result<()>
}
GzHeaderParsingState::Comment => {
if r.part.flg & FCOMMENT != 0 {
if None == r.part.header.comment {
if r.part.header.comment.is_none() {
r.part.header.comment = Some(Vec::new());
};
for byte in r.bytes() {
Expand Down Expand Up @@ -718,20 +718,20 @@ pub mod tests {
}

pub fn set_position(&mut self, pos: u64) {
return self.cursor.set_position(pos);
self.cursor.set_position(pos)
}

pub fn position(&mut self) -> u64 {
return self.cursor.position();
self.cursor.position()
}
}

impl Write for BlockingCursor {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
return self.cursor.write(buf);
self.cursor.write(buf)
}
fn flush(&mut self) -> io::Result<()> {
return self.cursor.flush();
self.cursor.flush()
}
}

Expand All @@ -751,7 +751,7 @@ pub mod tests {
}
Ok(_n) => {}
}
return r;
r
}
}
#[test]
Expand Down
10 changes: 5 additions & 5 deletions src/gz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ impl GzBuilder {
}
if let Some(filename) = filename {
flg |= FNAME;
header.extend(filename.as_bytes_with_nul().iter().map(|x| *x));
header.extend(filename.as_bytes_with_nul().iter().copied());
}
if let Some(comment) = comment {
flg |= FCOMMENT;
header.extend(comment.as_bytes_with_nul().iter().map(|x| *x));
header.extend(comment.as_bytes_with_nul().iter().copied());
}
header[0] = 0x1f;
header[1] = 0x8b;
Expand Down Expand Up @@ -285,14 +285,14 @@ mod tests {
let v = crate::random_bytes().take(1024).collect::<Vec<_>>();
for _ in 0..200 {
let to_write = &v[..thread_rng().gen_range(0..v.len())];
real.extend(to_write.iter().map(|x| *x));
real.extend(to_write.iter().copied());
w.write_all(to_write).unwrap();
}
let result = w.finish().unwrap();
let mut r = read::GzDecoder::new(&result[..]);
let mut v = Vec::new();
r.read_to_end(&mut v).unwrap();
assert!(v == real);
assert_eq!(v, real);
}

#[test]
Expand All @@ -301,7 +301,7 @@ mod tests {
let mut r = read::GzDecoder::new(read::GzEncoder::new(&v[..], Compression::default()));
let mut res = Vec::new();
r.read_to_end(&mut res).unwrap();
assert!(res == v);
assert_eq!(res, v);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/gz/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<W: Write> GzEncoder<W> {
self.inner.finish()?;

while self.crc_bytes_written < 8 {
let (sum, amt) = (self.crc.sum() as u32, self.crc.amount());
let (sum, amt) = (self.crc.sum(), self.crc.amount());
let buf = [
(sum >> 0) as u8,
(sum >> 8) as u8,
Expand Down Expand Up @@ -296,7 +296,7 @@ impl<W: Write> GzDecoder<W> {
| ((self.crc_bytes[5] as u32) << 8)
| ((self.crc_bytes[6] as u32) << 16)
| ((self.crc_bytes[7] as u32) << 24);
if crc != self.inner.get_ref().crc().sum() as u32 {
if crc != self.inner.get_ref().crc().sum() {
return Err(corrupt());
}
if amt != self.inner.get_ref().crc().amount() {
Expand Down Expand Up @@ -377,7 +377,7 @@ impl<W: Read + Write> Read for GzDecoder<W> {
mod tests {
use super::*;

const STR: &'static str = "Hello World Hello World Hello World Hello World Hello World \
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World \
Expand Down
16 changes: 6 additions & 10 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ pub struct Decompress {
inner: Inflate,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
/// Values which indicate the form of flushing to be used when compressing
/// in-memory data.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum FlushCompress {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand Down Expand Up @@ -80,14 +81,12 @@ pub enum FlushCompress {
/// The return value may indicate that the stream is not yet done and more
/// data has yet to be processed.
Finish = ffi::MZ_FINISH as isize,

#[doc(hidden)]
_Nonexhaustive,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
/// Values which indicate the form of flushing to be used when
/// decompressing in-memory data.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum FlushDecompress {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand All @@ -108,9 +107,6 @@ pub enum FlushDecompress {
/// The return value may indicate that the stream is not yet done and more
/// data has yet to be processed.
Finish = ffi::MZ_FINISH as isize,

#[doc(hidden)]
_Nonexhaustive,
}

/// The inner state for an error when decompressing
Expand Down Expand Up @@ -362,7 +358,7 @@ impl Compress {
unsafe {
let before = self.total_out();
let ret = {
let ptr = output.as_mut_ptr().offset(len as isize);
let ptr = output.as_mut_ptr().add(len);
let out = slice::from_raw_parts_mut(ptr, cap - len);
self.compress(input, out, flush)
};
Expand Down Expand Up @@ -503,7 +499,7 @@ impl Decompress {
unsafe {
let before = self.total_out();
let ret = {
let ptr = output.as_mut_ptr().offset(len as isize);
let ptr = output.as_mut_ptr().add(len);
let out = slice::from_raw_parts_mut(ptr, cap - len);
self.decompress(input, out, flush)
};
Expand Down
6 changes: 2 additions & 4 deletions src/zio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ where
// then we need to keep asking for more data because if we
// return that 0 bytes of data have been read then it will
// be interpreted as EOF.
Ok(Status::Ok) | Ok(Status::BufError) if read == 0 && !eof && !dst.is_empty() => {
continue
}
Ok(Status::Ok) | Ok(Status::BufError) | Ok(Status::StreamEnd) => return Ok(read),
Ok(Status::Ok | Status::BufError) if read == 0 && !eof && !dst.is_empty() => continue,
Ok(Status::Ok | Status::BufError | Status::StreamEnd) => return Ok(read),

Err(..) => {
return Err(io::Error::new(
Expand Down
Loading