From 0de6c4d001b7f526b5feeee43da7988211b8903a Mon Sep 17 00:00:00 2001 From: Ral Date: Fri, 28 Jul 2023 21:25:44 +0200 Subject: [PATCH] Some clippy lints --- .rustfmt.toml | 3 +++ src/checksum.rs | 3 ++- src/i2c.rs | 1 + src/io.rs | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..b8bfe30 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,3 @@ +edition = "2021" +max_width = 110 +newline_style = "Unix" diff --git a/src/checksum.rs b/src/checksum.rs index e9d50a6..424cfc7 100644 --- a/src/checksum.rs +++ b/src/checksum.rs @@ -1,6 +1,7 @@ // Compute the checksum over the bytes of a block. +#[allow(clippy::cast_possible_truncation)] pub fn checksum(bytes: &[u8]) -> u8 { - bytes.iter().fold(0u32, |x, y| x + (*y as u32)) as u8 + bytes.iter().fold(0u32, |x, y| x + u32::from(*y)) as u8 } // Validate the checksum diff --git a/src/i2c.rs b/src/i2c.rs index 840ee2c..e30279b 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -36,6 +36,7 @@ pub fn write_to_bus( // Write 8 bytes at a time for (i, chunk) in data.chunks_exact(8).enumerate() { // Memory address + #[allow(clippy::cast_possible_truncation)] let address = memory_address + (i as u8) * 8; let mut msgs = [ // Address to write to diff --git a/src/io.rs b/src/io.rs index a4eddd6..05bef3a 100644 --- a/src/io.rs +++ b/src/io.rs @@ -23,6 +23,7 @@ pub fn block_by_block_read( // Read remaining blocks match num_extensions { 0 => vec![], + #[allow(clippy::cast_possible_truncation)] _ => read(BLOCK_SIZE as u8, num_extensions * BLOCK_SIZE)?, } }