From d5c273687fb1ba07af976f35439daaa6129cb857 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sun, 24 Feb 2019 23:34:59 -0500 Subject: [PATCH] clippy saves the world, part 2 --- clippy.toml | 1 + src/durandal/bin.rs | 8 +++--- src/durandal/cenum.rs | 4 +-- src/durandal/err.rs | 8 +++--- src/durandal/file.rs | 6 ++-- src/durandal/fixed.rs | 5 ++-- src/durandal/image.rs | 6 ++-- src/durandal/sound.rs | 24 ++++++++-------- src/durandal/text.rs | 8 +++--- src/lib.rs | 51 ++++++++++++++++++++++++++++++++++ src/marathon/machdr.rs | 12 ++++---- src/marathon/map.rs | 52 +++++++++++++++++------------------ src/marathon/phy.rs | 62 +++++++++++++++++++++--------------------- src/marathon/pict.rs | 30 ++++++++------------ src/marathon/shp.rs | 12 ++++---- src/marathon/trm.rs | 2 +- src/marathon/wad.rs | 12 ++++---- 17 files changed, 175 insertions(+), 128 deletions(-) diff --git a/clippy.toml b/clippy.toml index c21b1f1..08a82b6 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,2 @@ single-char-binding-names-threshold = 10 +doc-valid-idents = ["QuickDraw"] diff --git a/src/durandal/bin.rs b/src/durandal/bin.rs index 5a5a857..6ca254f 100644 --- a/src/durandal/bin.rs +++ b/src/durandal/bin.rs @@ -157,12 +157,12 @@ pub fn rd_ofstable(b: &[u8], impl OptU16 { /// Creates an `OptU16` from a `u16`. - pub fn from_repr(n: u16) -> OptU16 + pub fn from_repr(n: u16) -> Self { if n == u16::max_value() { - OptU16(None) + Self(None) } else { - OptU16(NonZeroU16::new(n + 1)) + Self(NonZeroU16::new(n + 1)) } } @@ -187,7 +187,7 @@ impl OptU16 impl fmt::Debug for OptU16 { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.get() { None => write!(f, "None"), diff --git a/src/durandal/cenum.rs b/src/durandal/cenum.rs index b7b4d22..9ffc1d2 100644 --- a/src/durandal/cenum.rs +++ b/src/durandal/cenum.rs @@ -20,7 +20,7 @@ macro_rules! c_enum impl $E { - pub fn from_repr(n: $T) -> Result<$E, ReprError> + $V fn from_repr(n: $T) -> Result<$E, ReprError> { match n { $($value => Ok($E::$Enum),)+ @@ -38,7 +38,7 @@ mod test c_enum! { #[derive(Debug, PartialEq)] - pub enum TestEnum: u16 + enum TestEnum: u16 { 0 => Zero, 1 => One, diff --git a/src/durandal/err.rs b/src/durandal/err.rs index 09b4f83..0d0e413 100644 --- a/src/durandal/err.rs +++ b/src/durandal/err.rs @@ -35,7 +35,7 @@ impl Fail for ErrMsg {} impl fmt::Display for ReprError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "representation error (got {})", self.0) } @@ -43,7 +43,7 @@ impl fmt::Display for ReprError impl fmt::Debug for ReprError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } @@ -51,12 +51,12 @@ impl fmt::Debug for ReprError impl fmt::Display for ErrMsg { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {f.write_str(self.0)} + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {f.write_str(self.0)} } impl fmt::Debug for ErrMsg { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } diff --git a/src/durandal/file.rs b/src/durandal/file.rs index c9830fc..36b30c8 100644 --- a/src/durandal/file.rs +++ b/src/durandal/file.rs @@ -6,10 +6,10 @@ use std::fs; pub fn validate_folder_path(p: &str) -> ResultS<()> { let at = fs::metadata(p)?; - if !at.is_dir() { - Err(err_msg("not a directory")) - } else { + if at.is_dir() { Ok(()) + } else { + Err(err_msg("not a directory")) } } diff --git a/src/durandal/fixed.rs b/src/durandal/fixed.rs index ac32730..9e83e4c 100644 --- a/src/durandal/fixed.rs +++ b/src/durandal/fixed.rs @@ -19,6 +19,7 @@ macro_rules! define_fixed_type { pub fn set_bits(&mut self, bits: $UT) {self.0 = bits as $IT} pub const fn from_bits(bits: $UT) -> Self {$Type(bits as $IT)} pub fn integ(&self) -> $LT {(self.0 >> Self::FRACBITS) as $LT} + #[allow(trivial_numeric_casts)] pub fn fract(&self) -> u16 {(self.0 as $UT & Self::FRACMASK) as u16} pub fn mul_i(&self, n: $LT) -> Self {$Type(self.0 * $IT::from(n))} pub fn div_i(&self, n: $LT) -> Self {$Type(self.0 / $IT::from(n))} @@ -85,7 +86,7 @@ macro_rules! define_fixed_type { impl fmt::Display for $Type { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let prec = f.precision().unwrap_or(1); let widt = f.width().unwrap_or(0); @@ -106,7 +107,7 @@ macro_rules! define_fixed_type { impl fmt::Debug for $Type { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } diff --git a/src/durandal/image.rs b/src/durandal/image.rs index b2275e4..366d41f 100644 --- a/src/durandal/image.rs +++ b/src/durandal/image.rs @@ -81,7 +81,7 @@ pub trait Image fn get(&self, x: usize, y: usize) -> Option<&Self::Output> { if x < self.w() && y < self.h() { - Some(&self.index(x, y)) + Some(self.index(x, y)) } else { None } @@ -142,7 +142,7 @@ impl Image for Image8 impl Color16 { - pub const fn new(r: u16, g: u16, b: u16) -> Color16 {Color16(r, g, b)} + pub const fn new(r: u16, g: u16, b: u16) -> Self {Self(r, g, b)} } impl Color for Color16 @@ -155,7 +155,7 @@ impl Color for Color16 impl Color8 { - pub const fn new(r: u8, g: u8, b: u8) -> Color8 {Color8(r, g, b)} + pub const fn new(r: u8, g: u8, b: u8) -> Self {Self(r, g, b)} } impl Color for Color8 diff --git a/src/durandal/sound.rs b/src/durandal/sound.rs index 5739b8f..3c247bd 100644 --- a/src/durandal/sound.rs +++ b/src/durandal/sound.rs @@ -5,13 +5,13 @@ use std::io; pub fn write_wav(out: &mut impl io::Write, snd: &impl Sound) -> ResultS<()> { - let rate = u32::from(snd.rate()); - let bps = rate * 2; - let ssize = snd.len() as u32 * 2; - let fsize = 36 + ssize; + let rate = u32::from(snd.rate()); + let bps = rate * 2; + let dat_size = snd.len() as u32 * 2; + let hdr_size = 36 + dat_size; out.write_all(b"RIFF")?; - out.write_all(&u32::to_le_bytes(fsize))?; + out.write_all(&u32::to_le_bytes(hdr_size))?; out.write_all(b"WAVE")?; out.write_all(b"fmt ")?; out.write_all(&u32::to_le_bytes(16))?; @@ -22,7 +22,7 @@ pub fn write_wav(out: &mut impl io::Write, snd: &impl Sound) -> ResultS<()> out.write_all(&u16::to_le_bytes(2))?; // block alignment out.write_all(&u16::to_le_bytes(16))?; // bits per sample out.write_all(b"data")?; - out.write_all(&u32::to_le_bytes(ssize))?; + out.write_all(&u32::to_le_bytes(dat_size))?; for p in 0..snd.len() { let sample = snd.index(p); @@ -54,30 +54,30 @@ pub trait Sound impl Sound16 { - /// Creates a new Sound16. + /// Creates a new `Sound16`. pub fn new(rate: u16, lp_beg: usize, lp_end: usize, len: usize) -> Self { Self{rate, lp_beg, lp_end, data: Vec::with_capacity(len)} } - /// Creates a new Sound16 from an unsigned 8-bit stream. + /// Creates a new `Sound16` from an unsigned 8-bit stream. pub fn new_from_8(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) -> Self { - let mut snd = Sound16::new(rate, lp_beg, lp_end, b.len()); + let mut snd = Self::new(rate, lp_beg, lp_end, b.len()); for &sample in b { - snd.data.push(Sound16::sample_from_8(sample)); + snd.data.push(Self::sample_from_8(sample)); } snd } - /// Creates a new Sound16 from a signed 16-bit stream. + /// Creates a new `Sound16` from a signed 16-bit stream. pub fn new_from_16(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8]) -> Self { - let mut snd = Sound16::new(rate, lp_beg, lp_end, b.len() / 2); + let mut snd = Self::new(rate, lp_beg, lp_end, b.len() / 2); for i in (0..b.len()).step_by(2) { snd.data.push(i16::from_le_bytes([b[i], b[i + 1]])); diff --git a/src/durandal/text.rs b/src/durandal/text.rs index 13ab409..a9b385e 100644 --- a/src/durandal/text.rs +++ b/src/durandal/text.rs @@ -35,14 +35,14 @@ pub fn to_binsize(n: u64) -> String // terabytes, gigabytes, megabytes, kilobytes for i in (1..=4).rev() { - if n >= 1000u64.pow(i) { - let x = n as f64 / 1000f64.powi(i as i32); - return format!("{:1}{}", x, NAMES[i as usize - 1]); + let pow = 1000_u64.pow(i); + if n >= pow { + return format!("{:1}{}", n / 1000, NAMES[i as usize - 1]); } } // or, just bytes - format!("{} {}", n, if n != 1 {"bytes"} else {"byte"}) + format!("{} {}", n, if n == 1 {"byte"} else {"bytes"}) } /// Encodes or decodes a string in the terminal encryption format. diff --git a/src/lib.rs b/src/lib.rs index c983e0d..faf64a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,54 @@ +#![deny(anonymous_parameters)] // deny deprecated behaviour, warn otherwise +#![deny(bare_trait_objects)] +#![deny(elided_lifetimes_in_paths)] +#![warn(trivial_casts)] +#![warn(trivial_numeric_casts)] +#![deny(unreachable_pub)] +#![warn(unused_import_braces)] +#![warn(unused_qualifications)] +#![deny(clippy::all)] // clippy lints, deny all except nontrivial things +#![deny(clippy::clone_on_ref_ptr)] +#![deny(clippy::copy_iterator)] +#![deny(clippy::decimal_literal_representation)] +#![deny(clippy::default_trait_access)] +#![deny(clippy::doc_markdown)] +#![deny(clippy::empty_enum)] +#![deny(clippy::empty_line_after_outer_attr)] +#![deny(clippy::explicit_into_iter_loop)] +#![deny(clippy::explicit_iter_loop)] +#![deny(clippy::fallible_impl_from)] +#![deny(clippy::filter_map)] +#![deny(clippy::float_arithmetic)] // MUAHAHAHAHAHA +#![deny(clippy::float_cmp_const)] +#![deny(clippy::if_not_else)] +#![deny(clippy::invalid_upcast_comparisons)] +#![deny(clippy::items_after_statements)] +#![deny(clippy::large_digit_groups)] +#![deny(clippy::map_flatten)] +#![deny(clippy::match_same_arms)] +#![deny(clippy::mem_forget)] +#![deny(clippy::multiple_inherent_impl)] +#![deny(clippy::mut_mut)] +#![deny(clippy::mutex_integer)] +#![deny(clippy::needless_borrow)] +#![deny(clippy::needless_continue)] +#![deny(clippy::option_map_unwrap_or)] +#![deny(clippy::option_map_unwrap_or_else)] +#![deny(clippy::panicking_unwrap)] +#![deny(clippy::print_stdout)] +#![deny(clippy::pub_enum_variant_names)] +#![deny(clippy::replace_consts)] +#![deny(clippy::result_map_unwrap_or_else)] +#![deny(clippy::result_unwrap_used)] +#![deny(clippy::similar_names)] +#![deny(clippy::single_match_else)] +#![deny(clippy::string_add)] +#![deny(clippy::string_add_assign)] +#![deny(clippy::unnecessary_unwrap)] +#![deny(clippy::unseparated_literal_suffix)] +#![deny(clippy::use_self)] +#![deny(clippy::used_underscore_binding)] + #[macro_use] pub mod durandal; pub mod marathon; diff --git a/src/marathon/machdr.rs b/src/marathon/machdr.rs index d5555ab..660753b 100644 --- a/src/marathon/machdr.rs +++ b/src/marathon/machdr.rs @@ -2,7 +2,7 @@ use crate::durandal::bin::*; -/// Checks for an AppleSingle header. Returns offset to the resource fork. +/// Checks for an `AppleSingle` header. Returns offset to the resource fork. pub fn check_apple_single(b: &[u8]) -> Option { // check magic numbers @@ -32,7 +32,7 @@ pub fn check_apple_single(b: &[u8]) -> Option None } -/// Checks for a MacBinary II header. Returns offset to the resource fork. +/// Checks for a `MacBinary II` header. Returns offset to the resource fork. pub fn check_macbin(b: &[u8]) -> Option { // check legacy version, length, zero fill, and macbin2 version @@ -46,10 +46,10 @@ pub fn check_macbin(b: &[u8]) -> Option for &byte in b.iter().take(124) { for j in 8..16 { let d = u16::from(byte) << j; - if (d ^ crc) & 0x8000 != 0 { - crc = crc << 1 ^ 0x1021; - } else { + if (d ^ crc) & 0x8000 == 0 { crc <<= 1; + } else { + crc = crc << 1 ^ 0x1021; } } } @@ -62,7 +62,7 @@ pub fn check_macbin(b: &[u8]) -> Option } } -/// Reads a MacBin or AppleSingle header if there is one and returns the +/// Reads a `MacBin` or `AppleSingle` header if there is one and returns the /// offset from the start of the header to the resource fork (if one is found.) pub fn try_mac_header(b: &[u8]) -> usize { diff --git a/src/marathon/map.rs b/src/marathon/map.rs index 0caf305..f54f666 100644 --- a/src/marathon/map.rs +++ b/src/marathon/map.rs @@ -7,20 +7,20 @@ pub fn read_minf(b: &[u8]) -> ResultS { read_data! { 88, BE in b => - env_code = u16[0]; - physi_id = u16[2]; - music_id = u16[4]; - msn_flag = u16[6]; - env_flag = u16[8]; - levelnam = mac_roman_conv[18..84] nt; - ent_flag = u32[84]; + env_code = u16[0]; + physi_id = u16[2]; + music_id = u16[4]; + missi_flags = u16[6]; + envir_flags = u16[8]; + level_name = mac_roman_conv[18..84] nt; + entry_flags = u32[84]; } - let msn_flag = flag_ok!(MsnFlags, msn_flag)?; - let env_flag = flag_ok!(EnvFlags, env_flag)?; - let ent_flag = flag_ok!(EntFlags, ent_flag)?; - Ok(Minf{env_code, physi_id, music_id, msn_flag, env_flag, ent_flag, - levelnam}) + let missi_flags = flag_ok!(MsnFlags, missi_flags)?; + let envir_flags = flag_ok!(EnvFlags, envir_flags)?; + let entry_flags = flag_ok!(EntFlags, entry_flags)?; + Ok(Minf{env_code, physi_id, music_id, missi_flags, envir_flags, entry_flags, + level_name}) } pub fn read_lightfunc(b: &[u8]) -> ResultS @@ -399,12 +399,12 @@ pub struct Object #[derive(Debug, Serialize)] pub struct ObjectFreq { - rnd_loc: bool, - cnt_ini: u16, - cnt_min: u16, - cnt_max: u16, - cnt_rnd: u16, - chance: u16, + pub rnd_loc: bool, + pub cnt_ini: u16, + pub cnt_min: u16, + pub cnt_max: u16, + pub cnt_rnd: u16, + pub chance: u16, } #[derive(Debug, Serialize)] @@ -462,13 +462,13 @@ pub struct Platform #[derive(Debug, PartialEq, Serialize)] pub struct Minf { - pub env_code: u16, - pub physi_id: u16, - pub music_id: u16, - pub msn_flag: MsnFlags, - pub env_flag: EnvFlags, - pub ent_flag: EntFlags, - pub levelnam: String, + pub env_code: u16, + pub physi_id: u16, + pub music_id: u16, + pub missi_flags: MsnFlags, + pub envir_flags: EnvFlags, + pub entry_flags: EntFlags, + pub level_name: String, } bitflags! { @@ -683,7 +683,7 @@ c_enum! { impl std::fmt::Debug for Point { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "({}, {})", self.x, self.y) } diff --git a/src/marathon/phy.rs b/src/marathon/phy.rs index c537215..4d8d91b 100644 --- a/src/marathon/phy.rs +++ b/src/marathon/phy.rs @@ -620,12 +620,12 @@ c_enum! { #[derive(Debug, Serialize)] pub enum CasingType: u16 { - 0 => Rifle, - 1 => Pistol, - 2 => PistolLeft, - 3 => PistolRight, - 4 => SMG, - 65535 => None, + 0 => Rifle, + 1 => Pistol, + 2 => PistolLeft, + 3 => PistolRight, + 4 => SMG, + 0xFFFF => None, } } @@ -645,31 +645,31 @@ c_enum! { #[derive(Debug, Serialize)] pub enum DamageType: u16 { - 0 => Explosion, - 1 => ElectricalStaff, - 2 => Projectile, - 3 => Absorbed, - 4 => Flame, - 5 => HoundClaws, - 6 => AlienProjectile, - 7 => HulkSlap, - 8 => CompilerBolt, - 9 => FusionBolt, - 10 => HunterBolt, - 11 => Fist, - 12 => Teleporter, - 13 => Defender, - 14 => YetiClaws, - 15 => YetiProjectile, - 16 => Crushing, - 17 => Lava, - 18 => Suffocation, - 19 => Goo, - 20 => EnergyDrain, - 21 => OxygenDrain, - 22 => HummerBolt, - 23 => ShotgunProjectile, - 65535 => None, + 0 => Explosion, + 1 => ElectricalStaff, + 2 => Projectile, + 3 => Absorbed, + 4 => Flame, + 5 => HoundClaws, + 6 => AlienProjectile, + 7 => HulkSlap, + 8 => CompilerBolt, + 9 => FusionBolt, + 10 => HunterBolt, + 11 => Fist, + 12 => Teleporter, + 13 => Defender, + 14 => YetiClaws, + 15 => YetiProjectile, + 16 => Crushing, + 17 => Lava, + 18 => Suffocation, + 19 => Goo, + 20 => EnergyDrain, + 21 => OxygenDrain, + 22 => HummerBolt, + 23 => ShotgunProjectile, + 0xFFFF => None, } } diff --git a/src/marathon/pict.rs b/src/marathon/pict.rs index 65aad00..a2a6725 100644 --- a/src/marathon/pict.rs +++ b/src/marathon/pict.rs @@ -3,7 +3,7 @@ use crate::durandal::{bin::*, err::*, image::*}; use generic_array::*; -/// Reads a PixMap header. +/// Reads a `PixMap` header. fn read_pm_header<'a>(b: &'a [u8], pack: bool, clip: bool, @@ -57,7 +57,7 @@ fn read_pm_header<'a>(b: &'a [u8], Ok((&b[p..], Header{pitch, pack_t, depth, clut, rle})) } -/// Reads an indexed PixMap. +/// Reads an indexed `PixMap`. fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS { let clut = ok!(hdr.clut, "no CLUT in indexed mode")?; @@ -98,7 +98,7 @@ fn read_pm_ind(mut im: Image8, b: &[u8], hdr: Header) -> ResultS } } -/// Reads a R5G5B5 PixMap. +/// Reads a R5G5B5 `PixMap`. fn read_pm_16(mut im: Image8, b: &[u8], hdr: Header) -> ResultS { let mut p = 0; @@ -133,7 +133,7 @@ fn read_pm_16(mut im: Image8, b: &[u8], hdr: Header) -> ResultS } } -/// Reads a RGB8 PixMap. +/// Reads a RGB8 `PixMap`. fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS { let mut p = 0; @@ -185,7 +185,7 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS } } -/// Process a CopyBits operation. +/// Process a `CopyBits` operation. fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool) -> ResultS { @@ -200,13 +200,7 @@ fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool) } } -/// Process a CompressedQuickTime operation. -fn read_quicktime_c(_im: Image8, _b: &[u8]) -> ResultS -{ - unimplemented!() -} - -/// Load a PICT image. +/// Load a `PICT` image. pub fn load_pict(b: &[u8]) -> ResultS { read_data! { @@ -246,7 +240,7 @@ pub fn load_pict(b: &[u8]) -> ResultS } 0x8200 => { // CompressedQuickTime - return read_quicktime_c(im, &b[p..]); + unimplemented!(); } 0x00ff => { // OpEndPic @@ -308,7 +302,7 @@ pub fn load_pict(b: &[u8]) -> ResultS Err(err_msg("no image in data")) } -/// Read a colorTable structure. +/// Read a `ColorTable` structure. pub fn get_clut(b: &[u8]) -> ResultS<(Vec, usize)> { read_data! { @@ -333,7 +327,7 @@ pub fn get_clut(b: &[u8]) -> ResultS<(Vec, usize)> } // with device mapping, we ignore the index entirely - let n = if !dev {n} else {i}; + let n = if dev {i} else {n}; *ok!(clut.get_mut(n), "invalid index")? = Color8::new(r, g, b); @@ -411,9 +405,9 @@ pub fn expand_data(b: Vec, depth: u16) -> ResultS> for ch in b { match depth { - 4 => {for i in (0..=1).rev() {o.push(ch >> (i * 4) & 0xFu8);}} - 2 => {for i in (0..=3).rev() {o.push(ch >> (i * 2) & 0x3u8);}} - 1 => {for i in (0..=7).rev() {o.push(ch >> i & 0x1u8);}} + 4 => {for i in (0..=1).rev() {o.push(ch >> (i * 4) & 0xF_u8);}} + 2 => {for i in (0..=3).rev() {o.push(ch >> (i * 2) & 0x3_u8);}} + 1 => {for i in (0..=7).rev() {o.push(ch >> i & 0x1_u8);}} _ => bail!("invalid bit depth"), } } diff --git a/src/marathon/shp.rs b/src/marathon/shp.rs index e27247e..f38d2fc 100644 --- a/src/marathon/shp.rs +++ b/src/marathon/shp.rs @@ -206,16 +206,16 @@ pub fn read_shapes(b: &[u8]) -> ResultS> hi_len = u32[p + 16] as usize; } - let c_lo = if lo_ofs != u32::max_value() as usize { - Some(collection(&b[lo_ofs..lo_ofs + lo_len])?) - } else { + let c_lo = if lo_ofs == u32::max_value() as usize { None + } else { + Some(collection(&b[lo_ofs..lo_ofs + lo_len])?) }; - let c_hi = if hi_ofs != u32::max_value() as usize { - Some(collection(&b[hi_ofs..hi_ofs + hi_len])?) - } else { + let c_hi = if hi_ofs == u32::max_value() as usize { None + } else { + Some(collection(&b[hi_ofs..hi_ofs + hi_len])?) }; cl.push((c_lo, c_hi)); diff --git a/src/marathon/trm.rs b/src/marathon/trm.rs index b4e6813..7c8bde5 100644 --- a/src/marathon/trm.rs +++ b/src/marathon/trm.rs @@ -137,7 +137,7 @@ c_enum! { impl fmt::Debug for Group { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Group{{{:?} {} {}", self.ttype, self.pdata, self.lines)?; if !self.text.is_empty() { diff --git a/src/marathon/wad.rs b/src/marathon/wad.rs index 812100a..486142f 100644 --- a/src/marathon/wad.rs +++ b/src/marathon/wad.rs @@ -6,7 +6,7 @@ use std::{collections::BTreeMap, fmt}; impl Wad<'_> { - pub fn new(b: &[u8]) -> ResultS + pub fn new(b: &[u8]) -> ResultS> { read_data! { 128, BE in b => @@ -27,8 +27,8 @@ impl Wad<'_> _ => false, }; - let entsize = if !is_old {10} else {8 }; - let cnksize = if !is_old {16} else {12}; + let entsize = if is_old {8 } else {10}; + let cnksize = if is_old {12} else {16}; if entsize != wentsize { bail!("invalid entry size"); @@ -49,7 +49,7 @@ impl Wad<'_> index = u16[p + 8]; } - let index = if !is_old {index} else {i as u16}; + let index = if is_old {i as u16} else {index}; let cnkdata = &b[offset..offset + size]; let chunks = get_chunks(cnkdata, cnksize)?; @@ -64,7 +64,7 @@ impl Wad<'_> } } -fn get_chunks(b: &[u8], cnksize: usize) -> ResultS +fn get_chunks(b: &[u8], cnksize: usize) -> ResultS> { let mut chunks = ChunkMap::new(); let mut p = 0; @@ -127,7 +127,7 @@ c_enum! { impl fmt::Debug for Entry<'_> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Entry{{ ")?; for iden in self.chunks.keys() {