Skip to content

Commit

Permalink
Avoid returning String when callers expect &str
Browse files Browse the repository at this point in the history
Signed-off-by: Didier Wenzek <[email protected]>
  • Loading branch information
didier-wenzek committed Dec 19, 2024
1 parent bd5c7da commit 6780681
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/core/tedge_agent/src/operation_workflows/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions crates/core/tedge_api/src/workflow/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/tedge_api/src/workflow/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6780681

Please sign in to comment.