From dfda25111aa1b77448a26f18f17311d0af1b6deb Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 17 Dec 2022 08:23:19 -0500 Subject: [PATCH] Minor formatting and linter fixes --- src/crc.rs | 14 +++++--------- src/fiin.rs | 3 +-- src/gamedata.rs | 8 ++++---- src/sha1.rs | 15 +++++++-------- src/sqpack.rs | 4 ++-- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/crc.rs b/src/crc.rs index 731b987..22f9f8b 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -1,8 +1,8 @@ -pub struct JAMCRC { +pub struct Jamcrc { table: [u32; 256], } -impl JAMCRC { +impl Jamcrc { pub(crate) const fn new() -> Self { let mut table: [u32; 256] = [0u32; 256]; @@ -40,21 +40,17 @@ impl JAMCRC { #[cfg(test)] mod tests { use super::*; - use crate::fiin::FileInfo; - use std::fs::read; - use std::path::PathBuf; #[test] - fn basic_parsing() { + fn check_library() { use crc::{Crc, CRC_32_JAMCRC}; - use std::io::{Read, Seek, SeekFrom}; const JAMCR: Crc = Crc::::new(&CRC_32_JAMCRC); let bytes: [u8; 9] = [1, 1, 2, 4, 5, 6, 12, 12, 12]; - const crc: JAMCRC = JAMCRC::new(); + const CRC: Jamcrc = Jamcrc::new(); - assert_eq!(JAMCR.checksum(&bytes), crc.checksum(&bytes)) + assert_eq!(JAMCR.checksum(&bytes), CRC.checksum(&bytes)) } } diff --git a/src/fiin.rs b/src/fiin.rs index 91a75f6..ca2208c 100644 --- a/src/fiin.rs +++ b/src/fiin.rs @@ -1,7 +1,7 @@ use crate::gamedata::MemoryBuffer; use crate::sha1::Sha1; -use binrw::BinRead; use binrw::binrw; +use binrw::BinRead; use std::fs::read; use std::io::Cursor; @@ -71,7 +71,6 @@ impl FileInfo { #[cfg(test)] mod tests { - use super::*; use crate::fiin::FileInfo; use std::fs::read; use std::path::PathBuf; diff --git a/src/gamedata.rs b/src/gamedata.rs index 98fd361..659fe65 100755 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -175,7 +175,7 @@ impl GameData { let slice = index_file.entries.iter().find(|s| s.hash == hash); match slice { Some(entry) => { - let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id().into())?; + let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id())?; dat_file.read_from_offset(entry.bitfield.offset()) } @@ -301,11 +301,11 @@ impl GameData { .iter() .collect(); - std::fs::remove_dir_all(&repo_path) + fs::remove_dir_all(&repo_path) .ok() .ok_or(RepairError::FailedRepair(repository))?; - std::fs::create_dir_all(&repo_path) + fs::create_dir_all(&repo_path) .ok() .ok_or(RepairError::FailedRepair(repository))?; @@ -325,7 +325,7 @@ impl GameData { } }; - std::fs::write(&ver_path, new_version) + fs::write(&ver_path, new_version) .ok() .ok_or(RepairError::FailedRepair(repository))?; } diff --git a/src/sha1.rs b/src/sha1.rs index d92543c..d1e3521 100644 --- a/src/sha1.rs +++ b/src/sha1.rs @@ -24,12 +24,12 @@ pub trait SimdExt { fn simd_eq(self, rhs: Self) -> Self; } -impl SimdExt for fake::u32x4 { +impl SimdExt for u32x4 { fn simd_eq(self, rhs: Self) -> Self { if self == rhs { - fake::u32x4(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff) + u32x4(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff) } else { - fake::u32x4(0, 0, 0, 0) + u32x4(0, 0, 0, 0) } } } @@ -204,7 +204,7 @@ const DEFAULT_STATE: Sha1State = Sha1State { #[inline(always)] fn as_block(input: &[u8]) -> &[u8; 64] { unsafe { - assert!(input.len() == 64); + assert_eq!(input.len(), 64); let arr: &[u8; 64] = &*(input.as_ptr() as *const [u8; 64]); arr } @@ -663,9 +663,8 @@ impl str::FromStr for Digest { } let mut rv: Digest = Default::default(); for idx in 0..5 { - rv.data.state[idx] = - r#try!(u32::from_str_radix(&s[idx * 8..idx * 8 + 8], 16) - .map_err(|_| DigestParseError(()))); + rv.data.state[idx] = u32::from_str_radix(&s[idx * 8..idx * 8 + 8], 16) + .map_err(|_| DigestParseError(()))?; } Ok(rv) } @@ -674,7 +673,7 @@ impl str::FromStr for Digest { impl fmt::Display for Digest { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for i in self.data.state.iter() { - r#try!(write!(f, "{:08x}", i)); + write!(f, "{:08x}", i)?; } Ok(()) } diff --git a/src/sqpack.rs b/src/sqpack.rs index c9a32b4..0020344 100755 --- a/src/sqpack.rs +++ b/src/sqpack.rs @@ -1,10 +1,10 @@ use crate::compression::no_header_decompress; -use crate::crc::JAMCRC; +use crate::crc::Jamcrc; use crate::dat::{BlockHeader, CompressionMode}; use binrw::BinRead; use std::io::{Read, Seek, SeekFrom}; -const CRC: JAMCRC = JAMCRC::new(); +const CRC: Jamcrc = Jamcrc::new(); /// Calculates a hash for `index` files from a game path. pub fn calculate_hash(path: &str) -> u64 {