Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeWaka committed Nov 2, 2024
1 parent 9e740db commit fcd98e8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 54 deletions.
20 changes: 9 additions & 11 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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<NonZeroU32>`. As such, `From<Looping>` is
/// implemented for `Option<NonZeroU32>` as well as `Option<u32>`. If the more advanced combinators
Expand Down
77 changes: 34 additions & 43 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit fcd98e8

Please sign in to comment.