Skip to content

Commit

Permalink
Merge pull request #2854 from jarhodes314/tedge-config-empty-doc-comment
Browse files Browse the repository at this point in the history
Fix new clippy warning and add more span information to aid future debbuging of `define_tedge_config!`
  • Loading branch information
jarhodes314 authored May 2, 2024
2 parents aff310c + e1e6839 commit 7d7e12f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 34 deletions.
7 changes: 5 additions & 2 deletions crates/common/tedge_config_macros/impl/src/dto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use proc_macro2::TokenStream;
use quote::quote;
use quote::quote_spanned;
use syn::parse_quote_spanned;
use syn::spanned::Spanned;

Expand Down Expand Up @@ -48,13 +49,15 @@ pub fn generate(
}
}

quote! {
let doc_comment_attr =
(!doc_comment.is_empty()).then(|| quote_spanned!(name.span()=> #[doc = #doc_comment]));
quote_spanned! {name.span()=>
#[derive(Debug, Default, ::serde::Deserialize, ::serde::Serialize, PartialEq)]
// We will add more configurations in the future, so this is
// non_exhaustive (see
// https://doc.rust-lang.org/reference/attributes/type_system.html)
#[non_exhaustive]
#[doc = #doc_comment]
#doc_comment_attr
pub struct #name {
#(
// The fields are pub as that allows people to easily modify the
Expand Down
8 changes: 5 additions & 3 deletions crates/common/tedge_config_macros/impl/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ fn generate_structs(
})
.unzip();

Ok(quote! {
let doc_comment_attr =
(!doc_comment.is_empty()).then(|| quote_spanned!(name.span()=> #[doc = #doc_comment]));
Ok(quote_spanned! {name.span()=>
#[derive(::doku::Document, ::serde::Serialize, Debug, Clone)]
#[non_exhaustive]
#[doc = #doc_comment]
#doc_comment_attr
pub struct #name {
#(
#(#attrs)*
Expand All @@ -140,7 +142,7 @@ fn generate_structs(
pub struct #lr_names(::once_cell::sync::OnceCell<#lr_tys>);

impl From<#lr_names> for () {
fn from(_: #lr_names) -> () {}
fn from(_: #lr_names) {}
}

#lazy_reader_impls
Expand Down
2 changes: 1 addition & 1 deletion crates/common/tedge_utils/src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ mod tests {
let dir = TempTedgeDir::new();
let nested_dir = dir.dir("nested");

let mut stream = fs_notify_stream(&[&nested_dir.path()]).unwrap();
let mut stream = fs_notify_stream(&[nested_dir.path()]).unwrap();

// Test create
let file = nested_dir.file("file");
Expand Down
10 changes: 4 additions & 6 deletions crates/core/c8y_api/src/smartrest/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,10 @@ pub fn get_operations(dir: impl AsRef<Path>) -> Result<Operations, OperationsErr
Err(err) => return Err(OperationsError::FromIo(err)),
};

details.name = path
.file_name()
path.file_name()
.and_then(|filename| filename.to_str())
.ok_or_else(|| OperationsError::InvalidOperationName(path.to_owned()))?
.to_owned();
.clone_into(&mut details.name);

operations.add_operation(details);
}
Expand Down Expand Up @@ -251,11 +250,10 @@ pub fn get_operation(path: PathBuf) -> Result<Operation, OperationsError> {
Err(err) => return Err(OperationsError::FromIo(err)),
};

details.name = path
.file_name()
path.file_name()
.and_then(|filename| filename.to_str())
.ok_or_else(|| OperationsError::InvalidOperationName(path.to_owned()))?
.to_owned();
.clone_into(&mut details.name);

Ok(details)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/plugin_sm/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Plugins for ExternalPlugins {
}

fn update_default(&mut self, new_default: &Option<SoftwareType>) -> Result<(), SoftwareError> {
self.default_plugin_type = new_default.to_owned();
new_default.clone_into(&mut self.default_plugin_type);
Ok(())
}

Expand Down
7 changes: 4 additions & 3 deletions crates/core/tedge_api/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use serde::de::DeserializeOwned;
use serde::Deserialize;
use serde::Serialize;
use serde_json::json;
use std::fmt;
use time::OffsetDateTime;

/// A command instance with its target and its current state of execution
Expand Down Expand Up @@ -665,8 +666,8 @@ fn default_failure_reason() -> String {
"Unknown reason".to_string()
}

impl ToString for CommandStatus {
fn to_string(&self) -> String {
impl fmt::Display for CommandStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let str = match self {
CommandStatus::Init => "init",
CommandStatus::Scheduled => "scheduled",
Expand All @@ -675,7 +676,7 @@ impl ToString for CommandStatus {
CommandStatus::Failed { .. } => "failed",
CommandStatus::Unknown => "unknown",
};
str.to_string()
str.fmt(f)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_api/src/entity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl EntityStore {
/// The last parent in the list for any entity would always be the main device.
/// The list would be empty for the main device as it has no further parents.
pub fn ancestors(&self, entity_topic_id: &EntityTopicId) -> Result<Vec<&EntityTopicId>, Error> {
if self.entities.get(entity_topic_id).is_none() {
if !self.entities.contains_key(entity_topic_id) {
return Err(Error::UnknownEntity(entity_topic_id.to_string()));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_api/src/workflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl OperationWorkflow {
mut states: HashMap<StateName, OperationAction>,
) -> Result<Self, WorkflowDefinitionError> {
// The init state is required
if states.get("init").is_none() {
if !states.contains_key("init") {
return Err(WorkflowDefinitionError::MissingState {
state: "init".to_string(),
});
Expand Down
8 changes: 4 additions & 4 deletions crates/core/tedge_api/src/workflow/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ impl ExitHandlers {
self.timeout = default.timeout
}
if self.on_kill.is_none() {
self.on_kill = default.on_timeout.clone()
self.on_kill.clone_from(&default.on_timeout)
}
if self.on_error.is_none() {
self.on_error = default.on_error.clone()
self.on_error.clone_from(&default.on_error)
}

self
Expand Down Expand Up @@ -328,10 +328,10 @@ impl AwaitHandlers {
self.timeout = default.timeout
}
if self.on_timeout.is_none() {
self.on_timeout = default.on_timeout.clone()
self.on_timeout.clone_from(&default.on_timeout)
}
if self.on_error.is_none() {
self.on_error = default.on_error.clone()
self.on_error.clone_from(&default.on_error)
}

self
Expand Down
12 changes: 0 additions & 12 deletions crates/core/tedge_mapper/src/core/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ use tedge_config::TEdgeConfig;
pub trait TEdgeComponent: Sync + Send {
fn session_name(&self) -> &str;
async fn start(&self, tedge_config: TEdgeConfig, cfg_dir: &Path) -> Result<(), anyhow::Error>;

fn mqtt_config(&self) -> Result<mqtt_channel::Config, anyhow::Error> {
let tedge_config =
tedge_config::TEdgeConfig::try_new(tedge_config::TEdgeConfigLocation::default())?;

let mqtt_config = tedge_config
.mqtt_config()?
.with_session_name(self.session_name())
.with_clean_session(false);

Ok(mqtt_config)
}
}
2 changes: 2 additions & 0 deletions crates/extensions/c8y_http_proxy/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ impl Server for C8YJwtRetriever {
}

/// A JwtRetriever that simply always returns the same JWT token (possibly none)
#[cfg(test)]
pub(crate) struct ConstJwtRetriever {
pub token: String,
}

#[async_trait]
#[cfg(test)]
impl Server for ConstJwtRetriever {
type Request = JwtRequest;
type Response = JwtResult;
Expand Down

0 comments on commit 7d7e12f

Please sign in to comment.