From 1c5cd4ffdadf0b718f86e21e55fe45725695f37a Mon Sep 17 00:00:00 2001 From: Wyatt Herkamp Date: Thu, 13 Oct 2022 07:51:02 -0400 Subject: [PATCH] Fixed new Clippy Warnings --- examples/extract.rs | 2 +- examples/file_info.rs | 2 +- examples/write_dir.rs | 2 +- examples/write_sample.rs | 2 +- src/read.rs | 10 +++++----- src/spec.rs | 4 ++-- src/types.rs | 10 +++++----- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/extract.rs b/examples/extract.rs index 7b8860ca..3519ebaf 100644 --- a/examples/extract.rs +++ b/examples/extract.rs @@ -42,7 +42,7 @@ fn real_main() -> i32 { ); if let Some(p) = outpath.parent() { if !p.exists() { - fs::create_dir_all(&p).unwrap(); + fs::create_dir_all(p).unwrap(); } } let mut outfile = fs::File::create(&outpath).unwrap(); diff --git a/examples/file_info.rs b/examples/file_info.rs index 64969b66..0513c3a3 100644 --- a/examples/file_info.rs +++ b/examples/file_info.rs @@ -12,7 +12,7 @@ fn real_main() -> i32 { return 1; } let fname = std::path::Path::new(&*args[1]); - let file = fs::File::open(&fname).unwrap(); + let file = fs::File::open(fname).unwrap(); let reader = BufReader::new(file); let mut archive = zip::ZipArchive::new(reader).unwrap(); diff --git a/examples/write_dir.rs b/examples/write_dir.rs index 8cc561ff..20e599c1 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -114,7 +114,7 @@ fn doit( } let path = Path::new(dst_file); - let file = File::create(&path).unwrap(); + let file = File::create(path).unwrap(); let walkdir = WalkDir::new(src_dir); let it = walkdir.into_iter(); diff --git a/examples/write_sample.rs b/examples/write_sample.rs index b5749509..97a5515b 100644 --- a/examples/write_sample.rs +++ b/examples/write_sample.rs @@ -23,7 +23,7 @@ fn real_main() -> i32 { fn doit(filename: &str) -> zip::result::ZipResult<()> { let path = std::path::Path::new(filename); - let file = std::fs::File::create(&path).unwrap(); + let file = std::fs::File::create(path).unwrap(); let mut zip = zip::ZipWriter::new(file); diff --git a/src/read.rs b/src/read.rs index 0addf416..746c67b0 100644 --- a/src/read.rs +++ b/src/read.rs @@ -459,7 +459,7 @@ impl ZipArchive { fs::create_dir_all(&outpath)?; } else { if let Some(p) = outpath.parent() { - fs::create_dir_all(&p)?; + fs::create_dir_all(p)?; } let mut outfile = fs::File::create(&outpath)?; io::copy(file, &mut outfile)?; @@ -686,11 +686,11 @@ pub(crate) fn central_header_to_zip_file( reader.read_exact(&mut file_comment_raw)?; let file_name = match is_utf8 { - true => String::from_utf8_lossy(&*file_name_raw).into_owned(), + true => String::from_utf8_lossy(&file_name_raw).into_owned(), false => file_name_raw.clone().from_cp437(), }; let file_comment = match is_utf8 { - true => String::from_utf8_lossy(&*file_comment_raw).into_owned(), + true => String::from_utf8_lossy(&file_comment_raw).into_owned(), false => file_comment_raw.from_cp437(), }; @@ -1090,7 +1090,7 @@ pub fn read_zipfile_from_stream<'a, R: io::Read>( reader.read_exact(&mut extra_field)?; let file_name = match is_utf8 { - true => String::from_utf8_lossy(&*file_name_raw).into_owned(), + true => String::from_utf8_lossy(&file_name_raw).into_owned(), false => file_name_raw.clone().from_cp437(), }; @@ -1134,7 +1134,7 @@ pub fn read_zipfile_from_stream<'a, R: io::Read>( return unsupported_zip_error("The file length is not available in the local header"); } - let limit_reader = (reader as &'a mut dyn io::Read).take(result.compressed_size as u64); + let limit_reader = (reader as &'a mut dyn io::Read).take(result.compressed_size); let result_crc32 = result.crc32; let result_compression_method = result.compression_method; diff --git a/src/spec.rs b/src/spec.rs index 3ffcf732..2ed051b1 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -64,12 +64,12 @@ impl CentralDirectoryEnd { let mut pos = file_length - HEADER_SIZE; while pos >= search_upper_bound { - reader.seek(io::SeekFrom::Start(pos as u64))?; + reader.seek(io::SeekFrom::Start(pos))?; if reader.read_u32::()? == CENTRAL_DIRECTORY_END_SIGNATURE { reader.seek(io::SeekFrom::Current( BYTES_BETWEEN_MAGIC_AND_COMMENT_SIZE as i64, ))?; - let cde_start_pos = reader.seek(io::SeekFrom::Start(pos as u64))?; + let cde_start_pos = reader.seek(io::SeekFrom::Start(pos))?; return CentralDirectoryEnd::parse(reader).map(|cde| (cde, cde_start_pos)); } pos = match pos.checked_sub(1) { diff --git a/src/types.rs b/src/types.rs index 9b3b00c4..da4a42e3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -115,7 +115,7 @@ impl DateTime { let years = (datepart & 0b1111111000000000) >> 9; DateTime { - year: (years + 1980) as u16, + year: years + 1980, month: months as u8, day: days as u8, hour: hours as u8, @@ -172,10 +172,10 @@ impl DateTime { Ok(DateTime { year: (dt.year()) as u16, month: (dt.month()) as u8, - day: dt.day() as u8, - hour: dt.hour() as u8, - minute: dt.minute() as u8, - second: dt.second() as u8, + day: dt.day(), + hour: dt.hour(), + minute: dt.minute(), + second: dt.second(), }) } else { Err(())