Skip to content

Commit

Permalink
Merge pull request #113 from trifectatechfoundation/clippy-fixes
Browse files Browse the repository at this point in the history
fix clippy warnings
  • Loading branch information
folkertdev authored Dec 9, 2024
2 parents 84ca37a + 0b3ada9 commit 403f0af
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,12 @@ jobs:
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add clippy
- run: cargo clippy -- -D warnings
4 changes: 2 additions & 2 deletions src/bufread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<R: BufRead> Read for BzEncoder<R> {
// If we haven't ready any data and we haven't hit EOF yet, 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.
if read == 0 && !eof && buf.len() > 0 {
if read == 0 && !eof && !buf.is_empty() {
continue;
}
if ret == Status::StreamEnd {
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<R: BufRead> Read for BzDecoder<R> {
));
}

if read > 0 || buf.len() == 0 {
if read > 0 || buf.is_empty() {
return Ok(read);
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Compress {
);
Compress {
inner: Stream {
raw: raw,
raw,
_marker: marker::PhantomData,
},
}
Expand All @@ -146,7 +146,7 @@ impl Compress {
// apparently 0-length compression requests which don't actually make
// any progress are returned as BZ_PARAM_ERROR, which we don't want, to
// just translate to a success here.
if input.len() == 0 && action == Action::Run {
if input.is_empty() && action == Action::Run {
return Ok(Status::RunOk);
}
self.inner.raw.next_in = input.as_ptr() as *mut _;
Expand Down Expand Up @@ -182,12 +182,13 @@ 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, action)
};
output.set_len((self.total_out() - before) as usize + len);
return ret;

ret
}
}

Expand Down Expand Up @@ -215,7 +216,7 @@ impl Decompress {
assert_eq!(ffi::BZ2_bzDecompressInit(&mut *raw, 0, small as c_int), 0);
Decompress {
inner: Stream {
raw: raw,
raw,
_marker: marker::PhantomData,
},
}
Expand Down Expand Up @@ -254,12 +255,13 @@ 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)
};
output.set_len((self.total_out() - before) as usize + len);
return ret;

ret
}
}

Expand Down
15 changes: 6 additions & 9 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod tests {
let mut d = BzDecoder::new(c);
let mut data = vec![];
d.read_to_end(&mut data).unwrap();
assert!(data == &m[..]);
assert!(data == m[..]);
}

#[test]
Expand All @@ -239,18 +239,15 @@ mod tests {
let v = thread_rng()
.sample_iter(&Standard)
.take(1024)
.collect::<Vec<_>>();
.collect::<Vec<u8>>();
for _ in 0..200 {
result.extend(v.iter().map(|x: &u8| *x));
result.extend(v.iter().copied());
}

let mut d = BzDecoder::new(&result[..]);
let mut data = Vec::with_capacity(m.len());
unsafe {
data.set_len(m.len());
}
let mut data = vec![0; m.len()];
assert!(d.read(&mut data).unwrap() == m.len());
assert!(data == &m[..]);
assert!(data == m[..]);
}

#[test]
Expand Down Expand Up @@ -304,7 +301,7 @@ mod tests {
let mut r = BzDecoder::new(r);
let mut v2 = Vec::new();
r.read_to_end(&mut v2).unwrap();
assert!(v2.len() == 0);
assert!(v2.is_empty());
}

#[test]
Expand Down
15 changes: 7 additions & 8 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<W: Write> BzEncoder<W> {
}

fn dump(&mut self) -> io::Result<()> {
while self.buf.len() > 0 {
while !self.buf.is_empty() {
let n = match self.obj.as_mut().unwrap().write(&self.buf) {
Ok(n) => n,
Err(ref err) if err.kind() == io::ErrorKind::Interrupted => continue,
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<W: Write> Write for BzEncoder<W> {
.unwrap();
let written = (self.total_in() - total_in) as usize;

if written > 0 || data.len() == 0 {
if written > 0 || data.is_empty() {
return Ok(written);
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<W: Write> BzDecoder<W> {
}

fn dump(&mut self) -> io::Result<()> {
while self.buf.len() > 0 {
while !self.buf.is_empty() {
let n = match self.obj.as_mut().unwrap().write(&self.buf) {
Ok(n) => n,
Err(ref err) if err.kind() == io::ErrorKind::Interrupted => continue,
Expand All @@ -195,7 +195,7 @@ impl<W: Write> BzDecoder<W> {
/// function is called.
pub fn try_finish(&mut self) -> io::Result<()> {
while !self.done {
self.write(&[])?;
let _ = self.write(&[])?;
}
self.dump()
}
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<W: Write> Write for BzDecoder<W> {
if res == Status::StreamEnd {
self.done = true;
}
if written > 0 || data.len() == 0 || self.done {
if written > 0 || data.is_empty() || self.done {
return Ok(written);
}
}
Expand All @@ -272,14 +272,13 @@ mod tests {
use partial_io::quickcheck_types::{GenInterrupted, PartialWithErrors};
use partial_io::PartialWrite;
use std::io::prelude::*;
use std::iter::repeat;

#[test]
fn smoke() {
let d = BzDecoder::new(Vec::new());
let mut c = BzEncoder::new(d, Compression::default());
c.write_all(b"12834").unwrap();
let s = repeat("12345").take(100000).collect::<String>();
let s = "12345".repeat(100000);
c.write_all(s.as_bytes()).unwrap();
let data = c.finish().unwrap().finish().unwrap();
assert_eq!(&data[0..5], b"12834");
Expand All @@ -291,7 +290,7 @@ mod tests {
fn write_empty() {
let d = BzDecoder::new(Vec::new());
let mut c = BzEncoder::new(d, Compression::default());
c.write(b"").unwrap();
let _ = c.write(b"").unwrap();
let data = c.finish().unwrap().finish().unwrap();
assert_eq!(&data[..], b"");
}
Expand Down

0 comments on commit 403f0af

Please sign in to comment.