Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[package]
authors = ["Bennet Hattesen <bennet.hattesen@haw-hamburg.de>"]
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"
Expand All @@ -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"

Expand Down
1 change: 1 addition & 0 deletions src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
4 changes: 2 additions & 2 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H: FrameHandler>(
&mut self,
byte: u8,
Expand Down
9 changes: 5 additions & 4 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn encode_buffered(input: Slipmux) -> Vec<u8> {
}
let mut buffer: Vec<u8> = 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;
Expand Down Expand Up @@ -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..];
Expand Down Expand Up @@ -185,7 +186,7 @@ impl<'input> ChunkedEncoder<'input> {
break;
}
} else {
#[allow(
#[expect(
clippy::redundant_else,
clippy::if_not_else,
reason = "reflects logical decision tree"
Expand Down
20 changes: 10 additions & 10 deletions src/framehandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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!(),
}
}
Expand Down Expand Up @@ -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!(),
}
}
Expand Down Expand Up @@ -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!(),
}
}
Expand Down Expand Up @@ -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!(),
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down