From 6780681772594c3e76ab0bb41e55725a53d87307 Mon Sep 17 00:00:00 2001 From: Didier Wenzek Date: Thu, 19 Dec 2024 15:27:29 +0100 Subject: [PATCH] Avoid returning String when callers expect &str Signed-off-by: Didier Wenzek --- crates/core/tedge_agent/src/operation_workflows/persist.rs | 4 ++-- crates/core/tedge_api/src/workflow/state.rs | 3 +-- crates/core/tedge_api/src/workflow/supervisor.rs | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/core/tedge_agent/src/operation_workflows/persist.rs b/crates/core/tedge_agent/src/operation_workflows/persist.rs index 12ebb3b3ab..5541981e99 100644 --- a/crates/core/tedge_agent/src/operation_workflows/persist.rs +++ b/crates/core/tedge_agent/src/operation_workflows/persist.rs @@ -416,7 +416,7 @@ impl WorkflowRepository { } else if command_state.is_finished() { // Clear the cache if this happens to be the latest instance using that version of the workflow if let Some(version) = command_state.workflow_version() { - self.release_in_use_copy(&operation.to_string(), &version) + self.release_in_use_copy(&operation.to_string(), &version.to_string()) .await; } } @@ -429,7 +429,7 @@ impl WorkflowRepository { Some(new_state) if new_state.is_init() => { if let Some(version) = new_state.workflow_version() { - self.persist_workflow_definition(&operation.to_string(), &version) + self.persist_workflow_definition(&operation.to_string(), &version.to_string()) .await; } Ok(Some(new_state)) diff --git a/crates/core/tedge_api/src/workflow/state.rs b/crates/core/tedge_api/src/workflow/state.rs index b971148a56..baacfa7544 100644 --- a/crates/core/tedge_api/src/workflow/state.rs +++ b/crates/core/tedge_api/src/workflow/state.rs @@ -216,11 +216,10 @@ impl GenericCommandState { self.set_key_value(OP_LOG_PATH_KEY, path.as_ref().as_str()) } - pub fn workflow_version(&self) -> Option { + pub fn workflow_version(&self) -> Option<&str> { self.payload .get(OP_WORKFLOW_VERSION_KEY) .and_then(|val| val.as_str()) - .map(|str| str.to_string()) } pub fn with_workflow_version(mut self, version: &str) -> Self { diff --git a/crates/core/tedge_api/src/workflow/supervisor.rs b/crates/core/tedge_api/src/workflow/supervisor.rs index 835732561e..d381ec1bb1 100644 --- a/crates/core/tedge_api/src/workflow/supervisor.rs +++ b/crates/core/tedge_api/src/workflow/supervisor.rs @@ -192,7 +192,7 @@ impl WorkflowSupervisor { }); }; - let Some(version) = &command_state.workflow_version() else { + let Some(version) = command_state.workflow_version() else { return Err(WorkflowExecutionError::MissingVersion); }; @@ -421,7 +421,7 @@ impl WorkflowVersions { self.in_use.contains_key(BUILT_IN) } - fn get(&self, version: &WorkflowVersion) -> Result<&OperationWorkflow, WorkflowExecutionError> { + fn get(&self, version: &str) -> Result<&OperationWorkflow, WorkflowExecutionError> { self.in_use .get(version) .ok_or(WorkflowExecutionError::UnknownVersion {