From 5e635a89179978b7809b00b87a8c7da50610761e Mon Sep 17 00:00:00 2001 From: Marcel Guzik Date: Fri, 18 Oct 2024 17:03:28 +0200 Subject: [PATCH 1/2] chore: fix clippy lints Signed-off-by: Marcel Guzik --- crates/common/batcher/src/batchable.rs | 1 + crates/common/flockfile/src/unix.rs | 1 + crates/common/mqtt_channel/src/messages.rs | 2 +- crates/common/tedge_utils/src/timestamp.rs | 2 +- crates/common/upload/src/upload.rs | 2 ++ crates/core/c8y_api/src/smartrest/inventory.rs | 10 +++++++--- crates/core/c8y_api/src/smartrest/operations.rs | 1 + .../core/c8y_api/src/smartrest/smartrest_serializer.rs | 4 ++-- crates/core/tedge/src/bridge/config.rs | 7 ++----- crates/core/tedge_api/src/entity_store.rs | 8 -------- crates/core/tedge_api/src/measurement/parser.rs | 6 +++--- crates/core/tedge_write/src/api.rs | 2 +- .../c8y_mapper_ext/src/operations/handler.rs | 2 +- 13 files changed, 23 insertions(+), 25 deletions(-) diff --git a/crates/common/batcher/src/batchable.rs b/crates/common/batcher/src/batchable.rs index ffd845b0485..02ff0266a2a 100644 --- a/crates/common/batcher/src/batchable.rs +++ b/crates/common/batcher/src/batchable.rs @@ -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. diff --git a/crates/common/flockfile/src/unix.rs b/crates/common/flockfile/src/unix.rs index 8264982fbfe..711889349e0 100644 --- a/crates/common/flockfile/src/unix.rs +++ b/crates/common/flockfile/src/unix.rs @@ -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)] diff --git a/crates/common/mqtt_channel/src/messages.rs b/crates/common/mqtt_channel/src/messages.rs index d631f9ae474..47b116de0da 100644 --- a/crates/common/mqtt_channel/src/messages.rs +++ b/crates/common/mqtt_channel/src/messages.rs @@ -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 { diff --git a/crates/common/tedge_utils/src/timestamp.rs b/crates/common/tedge_utils/src/timestamp.rs index cdd805c601a..99f65c7d616 100644 --- a/crates/common/tedge_utils/src/timestamp.rs +++ b/crates/common/tedge_utils/src/timestamp.rs @@ -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 { diff --git a/crates/common/upload/src/upload.rs b/crates/common/upload/src/upload.rs index be1083dc947..c9609928c43 100644 --- a/crates/common/upload/src/upload.rs +++ b/crates/common/upload/src/upload.rs @@ -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)] @@ -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. diff --git a/crates/core/c8y_api/src/smartrest/inventory.rs b/crates/core/c8y_api/src/smartrest/inventory.rs index 773548ef135..3365bf42d48 100644 --- a/crates/core/c8y_api/src/smartrest/inventory.rs +++ b/crates/core/c8y_api/src/smartrest/inventory.rs @@ -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( @@ -141,9 +142,12 @@ impl From 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()]) } diff --git a/crates/core/c8y_api/src/smartrest/operations.rs b/crates/core/c8y_api/src/smartrest/operations.rs index 7734c4a5dfa..c8d88ca91a5 100644 --- a/crates/core/c8y_api/src/smartrest/operations.rs +++ b/crates/core/c8y_api/src/smartrest/operations.rs @@ -315,6 +315,7 @@ pub fn get_operation(path: PathBuf) -> Result { /// 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 { diff --git a/crates/core/c8y_api/src/smartrest/smartrest_serializer.rs b/crates/core/c8y_api/src/smartrest/smartrest_serializer.rs index 5568880db11..7b8cc7832ec 100644 --- a/crates/core/c8y_api/src/smartrest/smartrest_serializer.rs +++ b/crates/core/c8y_api/src/smartrest/smartrest_serializer.rs @@ -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() } diff --git a/crates/core/tedge/src/bridge/config.rs b/crates/core/tedge/src/bridge/config.rs index 737dc4e420c..4f37863cab5 100644 --- a/crates/core/tedge/src/bridge/config.rs +++ b/crates/core/tedge/src/bridge/config.rs @@ -49,11 +49,8 @@ impl BridgeConfig { pub fn serialize(&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)?; diff --git a/crates/core/tedge_api/src/entity_store.rs b/crates/core/tedge_api/src/entity_store.rs index 4396128faa1..dd5e3a58fad 100644 --- a/crates/core/tedge_api/src/entity_store.rs +++ b/crates/core/tedge_api/src/entity_store.rs @@ -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` -/// -/// - // In the future, root will be read from config const MQTT_ROOT: &str = "te"; diff --git a/crates/core/tedge_api/src/measurement/parser.rs b/crates/core/tedge_api/src/measurement/parser.rs index cf140837567..74638468a95 100644 --- a/crates/core/tedge_api/src/measurement/parser.rs +++ b/crates/core/tedge_api/src/measurement/parser.rs @@ -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, { @@ -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, { @@ -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, { diff --git a/crates/core/tedge_write/src/api.rs b/crates/core/tedge_write/src/api.rs index 1be8d6887fc..14d9939fa01 100644 --- a/crates/core/tedge_write/src/api.rs +++ b/crates/core/tedge_write/src/api.rs @@ -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. diff --git a/crates/extensions/c8y_mapper_ext/src/operations/handler.rs b/crates/extensions/c8y_mapper_ext/src/operations/handler.rs index 388fb2bf4fe..6b8ddad579c 100644 --- a/crates/extensions/c8y_mapper_ext/src/operations/handler.rs +++ b/crates/extensions/c8y_mapper_ext/src/operations/handler.rs @@ -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 From cc4c08274f6ff35271621d0df5d782866deaf12c Mon Sep 17 00:00:00 2001 From: Marcel Guzik Date: Fri, 18 Oct 2024 17:50:33 +0200 Subject: [PATCH 2/2] doctests change function name to main Signed-off-by: Marcel Guzik --- crates/core/tedge_actors/src/examples/mod.rs | 2 +- crates/core/tedge_actors/src/servers/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/core/tedge_actors/src/examples/mod.rs b/crates/core/tedge_actors/src/examples/mod.rs index 764da39e5e1..1d5e7a8128c 100644 --- a/crates/core/tedge_actors/src/examples/mod.rs +++ b/crates/core/tedge_actors/src/examples/mod.rs @@ -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 diff --git a/crates/core/tedge_actors/src/servers/mod.rs b/crates/core/tedge_actors/src/servers/mod.rs index bd78b3dd2b9..343a57e5b56 100644 --- a/crates/core/tedge_actors/src/servers/mod.rs +++ b/crates/core/tedge_actors/src/servers/mod.rs @@ -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.