Skip to content

Commit

Permalink
apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
tremwil committed Oct 4, 2024
1 parent 36eb1a0 commit 1a32b8b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crates/formats/src/io_ext/widestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub fn read_wide_cstring<BO: ByteOrder>(input: &[u8]) -> Result<&WStr<BO>, 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)
}
2 changes: 1 addition & 1 deletion crates/formats/src/matbin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, io};
use std::{io};

use byteorder::LE;
use thiserror::Error;
Expand Down
2 changes: 1 addition & 1 deletion crates/formats/src/msb/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;


use byteorder::LE;
use utf16string::WStr;
Expand Down
2 changes: 1 addition & 1 deletion crates/formats/src/msb/model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;


use byteorder::LE;
use utf16string::WStr;
Expand Down
2 changes: 1 addition & 1 deletion crates/formats/src/msb/parts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;


use byteorder::LE;
use utf16string::WStr;
Expand Down
2 changes: 1 addition & 1 deletion crates/formats/src/msb/point.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;


use byteorder::LE;
use utf16string::WStr;
Expand Down
2 changes: 1 addition & 1 deletion crates/formats/src/msb/route.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;


use byteorder::LE;
use utf16string::WStr;
Expand Down
14 changes: 7 additions & 7 deletions crates/formats/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -234,7 +234,7 @@ impl<BO: ByteOrder> ParamHeader<BO> {
/// 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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -393,12 +393,12 @@ impl<'a, T: traits::ParamFileLayout> Param<'a, T> {

/// Get the header of this param file.
pub fn header(&self) -> &ParamHeader<T::Endian> {
&self.header
self.header
}

/// Get the slice of row descriptors of this param file.
pub fn row_descriptors(&self) -> &[RowDescriptor<T>] {
&self.row_descriptors
self.row_descriptors
}
}

Expand Down Expand Up @@ -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]> {
Expand Down

0 comments on commit 1a32b8b

Please sign in to comment.