From 1a32b8bdfe8097f2b87721cc246cf4f9fdba719b Mon Sep 17 00:00:00 2001 From: William Tremblay Date: Fri, 4 Oct 2024 15:34:53 -0400 Subject: [PATCH] apply clippy suggestions --- crates/formats/src/io_ext/widestring.rs | 4 ++-- crates/formats/src/matbin/mod.rs | 2 +- crates/formats/src/msb/event.rs | 2 +- crates/formats/src/msb/model.rs | 2 +- crates/formats/src/msb/parts.rs | 2 +- crates/formats/src/msb/point.rs | 2 +- crates/formats/src/msb/route.rs | 2 +- crates/formats/src/param.rs | 14 +++++++------- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/formats/src/io_ext/widestring.rs b/crates/formats/src/io_ext/widestring.rs index 560d46a..8695a88 100644 --- a/crates/formats/src/io_ext/widestring.rs +++ b/crates/formats/src/io_ext/widestring.rs @@ -19,10 +19,10 @@ pub fn read_wide_cstring(input: &[u8]) -> Result<&WStr, ReadW // at the end of a read string) when the slice doesn't end at the terminator. let length = input .chunks_exact(2) - .position(|bytes| bytes == &[0, 0]) + .position(|bytes| bytes == [0, 0]) .ok_or(ReadWidestringError::NoEndFound)?; // Create a view that has a proper end let string_bytes = &input[..length * 2]; - Ok(WStr::from_utf16(string_bytes).map_err(|e| ReadWidestringError::InvalidUTF16)?) + WStr::from_utf16(string_bytes).map_err(|_e| ReadWidestringError::InvalidUTF16) } diff --git a/crates/formats/src/matbin/mod.rs b/crates/formats/src/matbin/mod.rs index 71d74b9..5830682 100644 --- a/crates/formats/src/matbin/mod.rs +++ b/crates/formats/src/matbin/mod.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, io}; +use std::{io}; use byteorder::LE; use thiserror::Error; diff --git a/crates/formats/src/msb/event.rs b/crates/formats/src/msb/event.rs index 3599f5f..db0a58d 100644 --- a/crates/formats/src/msb/event.rs +++ b/crates/formats/src/msb/event.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; + use byteorder::LE; use utf16string::WStr; diff --git a/crates/formats/src/msb/model.rs b/crates/formats/src/msb/model.rs index 8dca413..f3ba6a9 100644 --- a/crates/formats/src/msb/model.rs +++ b/crates/formats/src/msb/model.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; + use byteorder::LE; use utf16string::WStr; diff --git a/crates/formats/src/msb/parts.rs b/crates/formats/src/msb/parts.rs index c5bdb7e..a38b000 100644 --- a/crates/formats/src/msb/parts.rs +++ b/crates/formats/src/msb/parts.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; + use byteorder::LE; use utf16string::WStr; diff --git a/crates/formats/src/msb/point.rs b/crates/formats/src/msb/point.rs index 5ba8fd5..250f1d6 100644 --- a/crates/formats/src/msb/point.rs +++ b/crates/formats/src/msb/point.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; + use byteorder::LE; use utf16string::WStr; diff --git a/crates/formats/src/msb/route.rs b/crates/formats/src/msb/route.rs index b8d8a9c..d7f322c 100644 --- a/crates/formats/src/msb/route.rs +++ b/crates/formats/src/msb/route.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; + use byteorder::LE; use utf16string::WStr; diff --git a/crates/formats/src/param.rs b/crates/formats/src/param.rs index d672922..4cdac64 100644 --- a/crates/formats/src/param.rs +++ b/crates/formats/src/param.rs @@ -48,7 +48,7 @@ pub mod traits { } fn read_cstr(bytes: &[u8]) -> Option<&'_ Self> { - let nt_pos = bytes.chunks_exact(2).position(|b| b == &[0, 0])?; + let nt_pos = bytes.chunks_exact(2).position(|b| b == [0, 0])?; WStr::from_utf16(&bytes[..2 * nt_pos]).ok() } @@ -234,7 +234,7 @@ impl ParamHeader { /// Whether the param file containing this header uses UTF-16 encoding for strings, /// with endianness of the wide characters determined by [`ParamHeader::is_big_endian`]. pub fn is_unicode(&self) -> bool { - return (self.format_flags_2e & 1) != 0; + (self.format_flags_2e & 1) != 0 } /// If true, this param file uses 32-bit offsets and possibly has an extended header. @@ -353,14 +353,14 @@ impl<'a, T: traits::ParamFileLayout> Param<'a, T> { // If we have two rows, try to use them to guess the row size if row_descriptors.len() >= 2 { - let diff = (&row_descriptors[1]) + let diff = row_descriptors[1] .data_offset .into() .checked_sub(row_descriptors[0].data_offset.into()) .ok_or(ParamParseError::InvalidData)?; detected_row_size = Some(diff); } - if row_descriptors.len() >= 1 { + if !row_descriptors.is_empty() { // If the row name offset is set, this will be the string offset // provided it is not already set (as we have one row). // Otherwise, fall back to the (very unreliable) field in the header. @@ -393,12 +393,12 @@ impl<'a, T: traits::ParamFileLayout> Param<'a, T> { /// Get the header of this param file. pub fn header(&self) -> &ParamHeader { - &self.header + self.header } /// Get the slice of row descriptors of this param file. pub fn row_descriptors(&self) -> &[RowDescriptor] { - &self.row_descriptors + self.row_descriptors } } @@ -497,7 +497,7 @@ pub trait ParamCommon<'a> { impl<'a, T: traits::ParamFileLayout> ParamCommon<'a> for Param<'a, T> { fn file_bytes(&self) -> &[u8] { - &self.data + self.data } fn strings(&self) -> Option<&[u8]> {