Skip to content

Fix clippy warnings #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
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
18 changes: 9 additions & 9 deletions src/connections/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
Ok(())
}
e = handle => {
error!("Read handler unexpectedly terminated: {:#?}", e);
error!("Read handler unexpectedly terminated: {e:#?}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely on-board with this clippy rule but let's accept it 🙂

e
}
}
Expand All @@ -62,9 +62,9 @@ where
return Err(Error::InternalStreamError(InternalStreamError::Eof));
}
Ok(n) => {
trace!("Read {} bytes from stream", n);
trace!("Read {n} bytes from stream");
let data: IncomingStreamData = buffer[..n].to_vec().into();
trace!("Read data: {:?}", data);
trace!("Read data: {data:?}");

read_output_tx
.send(data)
Expand All @@ -74,7 +74,7 @@ where

// TODO check if port has fatally errored, and if so, tell UI
Err(e) => {
error!("Error reading from stream: {:?}", e);
error!("Error reading from stream: {e:?}");
return Err(Error::InternalStreamError(
InternalStreamError::StreamReadError {
source: Box::new(e),
Expand Down Expand Up @@ -123,12 +123,12 @@ where
debug!("Started write handler");

while let Some(message) = write_input_rx.recv().await {
trace!("Writing packet data: {:?}", message);
trace!("Writing packet data: {message:?}");

write_stream
.write(message.data())
.await
.inspect_err(|e| error!("Error writing to stream: {:?}", e))
.inspect_err(|e| error!("Error writing to stream: {e:?}"))
.map_err(InternalStreamError::write_error)?;
}

Expand Down Expand Up @@ -213,15 +213,15 @@ async fn start_heartbeat_handler(
match heartbeat_packet.encode(&mut buffer) {
Ok(_) => (),
Err(e) => {
error!("Error encoding heartbeat packet: {:?}", e);
error!("Error encoding heartbeat packet: {e:?}");
continue;
}
};

let packet_with_header = match format_data_packet(buffer.into()) {
Ok(p) => p,
Err(e) => {
error!("Error formatting heartbeat packet: {:?}", e);
error!("Error formatting heartbeat packet: {e:?}");
continue;
}
};
Expand All @@ -230,7 +230,7 @@ async fn start_heartbeat_handler(

write_input_tx
.send(packet_with_header)
.inspect_err(|e| error!("Error writing heartbeat packet to stream: {:?}", e))
.inspect_err(|e| error!("Error writing heartbeat packet to stream: {e:?}"))
.map_err(InternalStreamError::write_error)?;

log::info!("Sent heartbeat packet");
Expand Down
30 changes: 9 additions & 21 deletions src/connections/stream_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ impl StreamBuffer {
}
StreamBufferError::IncorrectFramingByte { found_framing_byte } => {
error!(
"Byte {} not equal to 0xc3, waiting for more data",
found_framing_byte
"Byte {found_framing_byte} not equal to 0xc3, waiting for more data"
);

break; // Wait for more data
Expand All @@ -97,34 +96,26 @@ impl StreamBuffer {
packet_size,
} => {
error!(
"Incomplete packet data, expected {} bytes, found {} bytes",
packet_size, buffer_size
"Incomplete packet data, expected {packet_size} bytes, found {buffer_size} bytes"
);

break; // Wait for more data
}
StreamBufferError::MissingMSB { msb_index } => {
error!(
"Could not find MSB at index {}, waiting for more data",
msb_index
);
error!("Could not find MSB at index {msb_index}, waiting for more data");

break; // Wait for more data
}
StreamBufferError::MissingLSB { lsb_index } => {
error!(
"Could not find LSB at index {}, waiting for more data",
lsb_index
);
error!("Could not find LSB at index {lsb_index}, waiting for more data");

break; // Wait for more data
}
StreamBufferError::MalformedPacket {
next_packet_start_idx,
} => {
error!(
"Detected malformed packet with next packet starting at index {}, purged malformed packet",
next_packet_start_idx
"Detected malformed packet with next packet starting at index {next_packet_start_idx}, purged malformed packet"
);

continue; // Don't need more data to continue, purge from buffer
Expand All @@ -145,7 +136,7 @@ impl StreamBuffer {
continue;
}
Err(e) => {
error!("Failed to send decoded packet: {}", e);
error!("Failed to send decoded packet: {e}");
break;
}
};
Expand Down Expand Up @@ -202,19 +193,16 @@ impl StreamBuffer {
let mut framing_index = StreamBuffer::find_framing_index_or_clear_buffer(buffer)?;

if framing_index != 0 {
debug!(
"Found framing byte at index {}, shifting buffer",
framing_index
);
debug!("Found framing byte at index {framing_index}, shifting buffer");

buffer.drain(0..framing_index);

log::trace!("Buffer after shifting: {:?}", buffer);
log::trace!("Buffer after shifting: {buffer:?}");

framing_index = StreamBuffer::find_framing_index_or_clear_buffer(buffer)?;
}

trace!("Returning framing index: {}", framing_index);
trace!("Returning framing index: {framing_index}");

Ok(framing_index)
}
Expand Down
11 changes: 6 additions & 5 deletions src/utils_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn build_serial_stream(
let mut serial_stream =
tokio_serial::SerialStream::open(&builder).map_err(|e| Error::StreamBuildError {
source: Box::new(e),
description: format!("Error opening serial port \"{}\"", port_name).to_string(),
description: format!("Error opening serial port \"{port_name}\"").to_string(),
})?;

serial_stream
Expand Down Expand Up @@ -187,12 +187,13 @@ pub async fn build_tcp_stream(
let stream = match tokio::time::timeout(timeout_duration, connection_future).await {
Ok(stream) => stream.map_err(|e| Error::StreamBuildError {
source: Box::new(e),
description: format!("Failed to connect to {}", address).to_string(),
description: format!("Failed to connect to {address}"),
})?,
Err(e) => {
return Err(Error::StreamBuildError{source:Box::new(e),description:format!(
"Timed out connecting to {}. Check that the radio is on, network is enabled, and the address is correct.",
address,
return Err(Error::StreamBuildError{
source: Box::new(e),
description: format!(
"Timed out connecting to {address}. Check that the radio is on, network is enabled, and the address is correct."
)});
}
};
Expand Down