From fcd98e828e098414f312196631897c8ccf124aa1 Mon Sep 17 00:00:00 2001 From: ZeWaka Date: Sat, 2 Nov 2024 01:44:03 -0700 Subject: [PATCH] fix clippy lints --- src/icon.rs | 20 +++++++------- src/lib.rs | 77 +++++++++++++++++++++++------------------------------ 2 files changed, 43 insertions(+), 54 deletions(-) diff --git a/src/icon.rs b/src/icon.rs index d26eab4..4294e70 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -169,7 +169,7 @@ impl Icon { }; let name = split_version[1].as_bytes(); - if !name.starts_with(&[b'\"']) || !name.ends_with(&[b'\"']) { + if !name.starts_with(b"\"") || !name.ends_with(b"\"") { return Err(DmiError::Generic(format!("Error loading icon: invalid name icon_state found in metadata, should be preceded and succeeded by double-quotes (\"): {:#?}", name))); }; let name = match name.len() { @@ -351,14 +351,11 @@ impl Icon { )) }; - match &icon_state.unknown_settings { - Some(hashmap) => { - for (setting, value) in hashmap.iter() { - signature.push_str(&format!("\t{} = {}\n", setting, value)); - } - } - None => (), - }; + if let Some(hashmap) = &icon_state.unknown_settings { + for (setting, value) in hashmap.iter() { + signature.push_str(&format!("\t{} = {}\n", setting, value)); + } + }; sprites.extend(icon_state.images.iter()); } @@ -406,8 +403,9 @@ impl Icon { /// animated [IconState] /// /// - `Indefinitely`: Loop repeatedly as long as the [IconState] is displayed -/// - `NTimes(NonZeroU32)`: Loop N times before freezing on the final frame. Stored as a `NonZeroU32` -/// for memory efficiency reasons, looping 0 times is an invalid state. +/// - `NTimes(NonZeroU32)`: Loop N times before freezing on the final frame. Stored as a `NonZeroU32` +/// +/// For memory efficiency reasons, looping 0 times is an invalid state. /// /// This type is effectively a newtype of `Option`. As such, `From` is /// implemented for `Option` as well as `Option`. If the more advanced combinators diff --git a/src/lib.rs b/src/lib.rs index 68f5ed0..102c021 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,49 +140,40 @@ impl RawDmi { ))); }; - match &self.chunk_ztxt { - Some(chunk_ztxt) => { - let bytes_written = chunk_ztxt.save(&mut writter)?; - total_bytes_written += bytes_written; - if bytes_written < u32::from_be_bytes(chunk_ztxt.data_length) as usize + 12 { - return Err(error::DmiError::Generic(format!( - "Failed to save DMI. Buffer unable to hold the data, only {} bytes written.", - total_bytes_written - ))); - }; - } - None => (), - }; - - match &self.chunk_plte { - Some(chunk_plte) => { - let bytes_written = chunk_plte.save(&mut writter)?; - total_bytes_written += bytes_written; - if bytes_written < u32::from_be_bytes(chunk_plte.data_length) as usize + 12 { - return Err(error::DmiError::Generic(format!( - "Failed to save DMI. Buffer unable to hold the data, only {} bytes written.", - total_bytes_written - ))); - }; - } - None => (), - }; - - match &self.other_chunks { - Some(other_chunks) => { - for chunk in other_chunks { - let bytes_written = chunk.save(&mut writter)?; - total_bytes_written += bytes_written; - if bytes_written < u32::from_be_bytes(chunk.data_length) as usize + 12 { - return Err(error::DmiError::Generic(format!( - "Failed to save DMI. Buffer unable to hold the data, only {} bytes written.", - total_bytes_written - ))); - }; - } - } - None => (), - } + if let Some(chunk_ztxt) = &self.chunk_ztxt { + let bytes_written = chunk_ztxt.save(&mut writter)?; + total_bytes_written += bytes_written; + if bytes_written < u32::from_be_bytes(chunk_ztxt.data_length) as usize + 12 { + return Err(error::DmiError::Generic(format!( + "Failed to save DMI. Buffer unable to hold the data, only {} bytes written.", + total_bytes_written + ))); + }; + }; + + if let Some(chunk_plte) = &self.chunk_plte { + let bytes_written = chunk_plte.save(&mut writter)?; + total_bytes_written += bytes_written; + if bytes_written < u32::from_be_bytes(chunk_plte.data_length) as usize + 12 { + return Err(error::DmiError::Generic(format!( + "Failed to save DMI. Buffer unable to hold the data, only {} bytes written.", + total_bytes_written + ))); + }; + }; + + if let Some(other_chunks) = &self.other_chunks { + for chunk in other_chunks { + let bytes_written = chunk.save(&mut writter)?; + total_bytes_written += bytes_written; + if bytes_written < u32::from_be_bytes(chunk.data_length) as usize + 12 { + return Err(error::DmiError::Generic(format!( + "Failed to save DMI. Buffer unable to hold the data, only {} bytes written.", + total_bytes_written + ))); + }; + } + } for chunk in &self.chunks_idat { let bytes_written = chunk.save(&mut writter)?;