diff --git a/Cargo.toml b/Cargo.toml index efc3349..4ec7243 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,10 @@ [package] authors = ["Bennet Hattesen "] categories = ["encoding"] -edition = "2024" description = "Slipmux de- and encoding" +edition = "2024" homepage = "https://github.com/teufelchen1/slipmux" keywords = ["slip", "serial", "uart", "coap", "no_std"] - license = "MIT OR Apache-2.0" name = "slipmux" readme = "README.md" @@ -22,11 +21,12 @@ unsafe_code = "forbid" [lints.clippy] pedantic = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 } +allow_attributes = "warn" cargo_common_metadata = "warn" let_underscore_untyped = "warn" +min_ident_chars = "warn" str_to_string = "warn" -cast_possible_truncation = "allow" option-if-let-else = "allow" single_match_else = "allow" diff --git a/src/checksum.rs b/src/checksum.rs index 0a06b00..d91598c 100644 --- a/src/checksum.rs +++ b/src/checksum.rs @@ -57,6 +57,7 @@ const FCS_LOOKUP: [u16; 256] = [ 0x3de3, 0x2c6a, 0x1ef1, 0x0f78, ]; +#[expect(clippy::cast_possible_truncation, reason = "truncation is wanted")] pub const fn fcs16_byte(fcs: u16, byte: u8) -> u16 { (fcs >> 8) ^ FCS_LOOKUP[(fcs as u8 ^ byte) as usize] } diff --git a/src/decoder.rs b/src/decoder.rs index cba5654..b1084a0 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -79,8 +79,8 @@ impl Decoder { /// /// Will return `Err` if either an unkown frame type is encountered OR the checksum of a /// configuration frame is bad OR a frame got aborted. - #[allow(clippy::match_same_arms)] - #[allow(clippy::too_many_lines)] + #[expect(clippy::match_same_arms)] + #[expect(clippy::too_many_lines)] pub fn decode( &mut self, byte: u8, diff --git a/src/encode.rs b/src/encode.rs index 7274215..37d8f34 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -45,9 +45,9 @@ pub fn encode_buffered(input: Slipmux) -> Vec { } let mut buffer: Vec = vec![]; let length = match input { - Slipmux::Diagnostic(s) => { - buffer.resize(space_requirement(s.len()), 0); - encode(FrameType::Diagnostic, s.as_bytes(), &mut buffer) + Slipmux::Diagnostic(message) => { + buffer.resize(space_requirement(message.len()), 0); + encode(FrameType::Diagnostic, message.as_bytes(), &mut buffer) } Slipmux::Configuration(conf) => { const CHECKSUM_BYTES: usize = 2; @@ -135,6 +135,7 @@ impl<'input> ChunkedEncoder<'input> { /// Advance whichever slice was just selected in [`Self::slice_to_encode()`] by some amount of /// bytes. + #[expect(clippy::cast_possible_truncation)] // TODO: should this be fixed? fn advance_slice(&mut self, amount: usize) { if !self.header.is_empty() { self.header = &self.header[amount..]; @@ -185,7 +186,7 @@ impl<'input> ChunkedEncoder<'input> { break; } } else { - #[allow( + #[expect( clippy::redundant_else, clippy::if_not_else, reason = "reflects logical decision tree" diff --git a/src/framehandler.rs b/src/framehandler.rs index 99c8b61..82ec4bd 100644 --- a/src/framehandler.rs +++ b/src/framehandler.rs @@ -206,8 +206,8 @@ impl FrameHandler for BufferedFrameHandler { self.subhandler.packet_buffer.clear(); } } - Some(e) => { - self.results.push(Err(e)); + Some(error) => { + self.results.push(Err(error)); self.subhandler.diagnostic_buffer.clear(); self.subhandler.configuration_buffer.clear(); self.subhandler.packet_buffer.clear(); @@ -404,7 +404,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } } @@ -440,7 +440,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Configuration(s) => assert_eq!(s, b"Hello World!"), + Slipmux::Configuration(config) => assert_eq!(config, b"Hello World!"), _ => unreachable!(), } } @@ -506,7 +506,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } } @@ -544,7 +544,7 @@ mod tests { assert_eq!(results.len(), 1); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } } @@ -607,8 +607,8 @@ mod tests { for results in results_arr { for slipframe in results { match slipframe { - Ok(Slipmux::Diagnostic(s)) => { - assert_eq!(s, "Hello World!"); + Ok(Slipmux::Diagnostic(message)) => { + assert_eq!(message, "Hello World!"); } Ok(Slipmux::Configuration(_conf)) => { // Do stuff @@ -695,13 +695,13 @@ mod tests { assert_eq!(results.len(), 2); let frame = results.pop().unwrap(); match frame.unwrap() { - Slipmux::Diagnostic(s) => assert_eq!(s, "Hello World!"), + Slipmux::Diagnostic(message) => assert_eq!(message, "Hello World!"), _ => unreachable!(), } let frame = results.pop().unwrap(); match frame { Ok(_) => unreachable!(), - Err(e) => assert!(matches!(e, Error::Abort)), + Err(error) => assert!(matches!(error, Error::Abort)), } } } diff --git a/src/lib.rs b/src/lib.rs index 85c2fd8..87d7c9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -261,8 +261,8 @@ mod tests { assert_eq!(3, frames.len()); for slipframe in frames { match slipframe { - Ok(Slipmux::Diagnostic(s)) => { - assert_eq!(s, "Hello World!"); + Ok(Slipmux::Diagnostic(message)) => { + assert_eq!(message, "Hello World!"); } Ok(Slipmux::Configuration(conf)) => { assert_eq!(conf, Packet::new().to_bytes().unwrap());