Skip to content
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

chore: Fix Rust 1.82 clippy lints #3195

Merged
merged 2 commits into from
Oct 18, 2024
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
1 change: 1 addition & 0 deletions crates/common/batcher/src/batchable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::hash::Hash;
use time::OffsetDateTime;

/// Implement this interface for the items that you want batched.
///
/// No items with the same key will go in the same batch.
/// The event_time of the item will determine how items are grouped,
/// dependent on how the batcher is configured.
Expand Down
1 change: 1 addition & 0 deletions crates/common/flockfile/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl FlockfileError {
}

/// flockfile creates a lockfile in the filesystem under `/run/lock` and then creates a filelock using system fcntl with flock.
///
/// flockfile will automatically remove lockfile on application exit and the OS should cleanup the filelock afterwards.
/// If application exits unexpectedly the filelock will be dropped, but the lockfile will not be removed unless handled in signal handler.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/mqtt_channel/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<'de> Deserialize<'de> for DebugPayload {
{
struct DebugPayloadVisitor;

impl<'de> serde::de::Visitor<'de> for DebugPayloadVisitor {
impl serde::de::Visitor<'_> for DebugPayloadVisitor {
type Value = DebugPayload;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion crates/common/tedge_utils/src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where

struct IsoOrUnixVisitor;

impl<'de> de::Visitor<'de> for IsoOrUnixVisitor {
impl de::Visitor<'_> for IsoOrUnixVisitor {
type Value = IsoOrUnix;

fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
Expand Down
2 changes: 2 additions & 0 deletions crates/common/upload/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn default_backoff() -> ExponentialBackoff {
}

/// Auto tries to detect the mime from the given file extension without direct file access.
///
/// Custom sets a custom Content-Type.
/// If multipart request is needed, choose FormData.
#[derive(Debug, Clone, Eq, PartialEq)]
Expand All @@ -40,6 +41,7 @@ pub enum ContentType {
}

/// Dataset to construct reqwest::multipart::Form.
///
/// To avoid using reqwest::multipart::Form inside the ContentType enum
/// since reqwest::multipart::Form doesn't support Copy or Clone.
/// If mime is None, the mime will be guessed while uploading a file.
Expand Down
10 changes: 7 additions & 3 deletions crates/core/c8y_api/src/smartrest/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::time::Duration;
use tedge_config::TopicPrefix;

/// Create a SmartREST message for creating a child device under the given ancestors.
///
/// The provided ancestors list must contain all the parents of the given device
/// starting from its immediate parent device.
pub fn child_device_creation_message(
Expand Down Expand Up @@ -141,9 +142,12 @@ impl From<C8ySmartRestSetInterval117> for MqttMessage {
}
}

/// Create a SmartREST payload for setting/updating the current state of the target profile
/// in its own managed object. When all individual operations are finished (i.e. firmware update, software update
/// and configuration update), the `profile_executed` field should be set to `true`, otherwise it should be `false`.
/// Create a SmartREST payload for setting/updating the current state of the
/// target profile in its own managed object.
///
/// When all individual operations are finished (i.e. firmware update, software
/// update and configuration update), the `profile_executed` field should be set
/// to `true`, otherwise it should be `false`.
pub fn set_c8y_profile_target_payload(profile_executed: bool) -> String {
fields_to_csv_string(&["121", &profile_executed.to_string()])
}
Expand Down
1 change: 1 addition & 0 deletions crates/core/c8y_api/src/smartrest/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ pub fn get_operation(path: PathBuf) -> Result<Operation, OperationsError> {

/// depending on which editor you use, temporary files could be created that contain the name of
/// the file.
///
/// this `operation_name_is_valid` fn will ensure that only files that do not contain
/// any special characters are allowed.
pub fn is_valid_operation_name(operation: &str) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/c8y_api/src/smartrest/smartrest_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ impl C8yOperation for CumulocitySupportedOperations {
}
}

impl<'a> C8yOperation for &'a str {
impl C8yOperation for &str {
fn name(&self) -> &str {
self
}
}

impl<'a> C8yOperation for &'a String {
impl C8yOperation for &String {
fn name(&self) -> &str {
self.as_str()
}
Expand Down
7 changes: 2 additions & 5 deletions crates/core/tedge/src/bridge/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ impl BridgeConfig {
pub fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
writeln!(writer, "### Bridge")?;
writeln!(writer, "connection {}", self.connection)?;
match &self.remote_username {
Some(name) => {
writeln!(writer, "remote_username {}", name)?;
}
None => {}
if let Some(name) = &self.remote_username {
writeln!(writer, "remote_username {}", name)?;
}
writeln!(writer, "address {}", self.address)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_actors/src/examples/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! # use tedge_actors::{Actor, Builder, ChannelError, MessageReceiver, Sender, NoConfig, ServerActor, ServerMessageBox, ServerMessageBoxBuilder, SimpleMessageBox, SimpleMessageBoxBuilder, Service, MessageSink, MessageSource};
//! # use crate::tedge_actors::examples::calculator_server::*;
//! # #[tokio::main]
//! # async fn main_test() -> Result<(),ChannelError> {
//! # async fn main() -> Result<(),ChannelError> {
//! #
//!
//! // Building a box to hold 16 pending requests for the calculator server actor
Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_actors/src/servers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//! #
//! #[cfg(feature = "test-helpers")]
//! # #[tokio::main]
//! # async fn main_test() {
//! # async fn main() {
//! # use tedge_actors::Service;
//! #
//! // As for any actor, one needs a handle to the message box of the server.
Expand Down
8 changes: 0 additions & 8 deletions crates/core/tedge_api/src/entity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ use std::fmt::Display;
use std::path::Path;
use thiserror::Error;

/// Represents an "Entity topic identifier" portion of the MQTT topic
///
/// Example:
/// - topic: `te/device/dev1/service/myservice/m//my_measurement`
/// - entity id: `device/dev1/service/myservice`
///
/// <https://thin-edge.github.io/thin-edge.io/next/references/mqtt-api/#group-identifier>

Comment on lines -33 to -40
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to attach this definition to a type or a module, rather than remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment is for EntityTopicId. The struct was moved to another module along with the comment, but the comment in this module wasn't deleted.

/// Represents an "Entity topic identifier" portion of the MQTT topic
///
/// An entity identifier is a fixed 4-segment group, as such any 4 topic
/// segments that come after the root are considered a part of an identifier,
/// even if they contain values usually present in the channel group, e.g.
/// `/m/`.
///
/// If the topic ends before the expected 4 segments, the remaining segments are
/// filled by empty segments (`//`).
///
/// # Example
/// - topic: `te/device/dev1/service/myservice/m//my_measurement`
/// - entity id: `device/dev1/service/myservice`
///
/// # Reference
/// https://thin-edge.github.io/thin-edge.io/next/references/mqtt-api/#group-identifier
#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)]
pub struct EntityTopicId(String);

// In the future, root will be read from config
const MQTT_ROOT: &str = "te";

Expand Down
6 changes: 3 additions & 3 deletions crates/core/tedge_api/src/measurement/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct ThinEdgeValueParser<'key, 'vis, T> {
visitor: &'vis mut T,
}

impl<'vis, 'de, T> de::Visitor<'de> for ThinEdgeJsonParser<'vis, T>
impl<'de, T> de::Visitor<'de> for ThinEdgeJsonParser<'_, T>
where
T: MeasurementVisitor,
{
Expand Down Expand Up @@ -119,7 +119,7 @@ where
}
}

impl<'key, 'vis, 'de, T> de::Visitor<'de> for ThinEdgeValueParser<'key, 'vis, T>
impl<'de, T> de::Visitor<'de> for ThinEdgeValueParser<'_, '_, T>
where
T: MeasurementVisitor,
{
Expand Down Expand Up @@ -240,7 +240,7 @@ where
///
/// As we are passing the parsed data over to the embedded visitor, all of our parsers do not
/// produce a value, so we use the empty tuple type.
impl<'key, 'vis, 'de, T> DeserializeSeed<'de> for ThinEdgeValueParser<'key, 'vis, T>
impl<'de, T> DeserializeSeed<'de> for ThinEdgeValueParser<'_, '_, T>
where
T: MeasurementVisitor,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_write/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct CopyOptions<'a> {
pub group: Option<&'a str>,
}

impl<'a> CopyOptions<'a> {
impl CopyOptions<'_> {
/// Copies the file by spawning new tedge-write process.
///
/// Stdin and Stdout are UTF-8.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl OperationHandler {
///
/// The panic in the operation task has to happen first, and then another message with the same
/// command id has to be handled for the call to `.handle()` to panic.

//
// but there's a problem: in practice, when a panic in a child task happens, .handle() will
// never get called for that operation again. Operation task itself sends the messages, so if
// they can't be sent over MQTT because of a panic, they won't be handled, won't be joined, so
Expand Down