Skip to content

refactor: use unwrap_or_default for optional metadata maps - #329

Merged
mikeee merged 1 commit into
dapr:mainfrom
immanuwell:refactor/metadata-unwrap-or-default
Jun 15, 2026
Merged

refactor: use unwrap_or_default for optional metadata maps#329
mikeee merged 1 commit into
dapr:mainfrom
immanuwell:refactor/metadata-unwrap-or-default

Conversation

@immanuwell

Copy link
Copy Markdown
Contributor

5 methods in client/mod.rs all have the same verbose pattern for handling optional metadata:

let mut mdata = HashMap::<String, String>::new();
if let Some(m) = metadata {
    mdata = m;
}

This is just a roundabout way of writing metadata.unwrap_or_default(). Swaps all 5 instances for that. No behavior change - HashMap::default() is identical to HashMap::new().

Also removes the unnecessary mut on the bindings where the map isn't modified after init (4 out of 5 cases).

To reproduce the pattern before the fix:

grep -n "let mut mdata = HashMap" dapr/src/client/mod.rs

Signed-off-by: Immanuel Tikhonov <pchpr.00@list.ru>
Signed-off-by: immanuwell <pchpr.00@list.ru>
@immanuwell
immanuwell requested review from a team as code owners June 6, 2026 11:24
@mikeee
mikeee requested a review from Copilot June 15, 2026 17:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors repeated optional-metadata handling in dapr/src/client/mod.rs by replacing a verbose HashMap::new() + if let Some(...) pattern with the idiomatic metadata.unwrap_or_default(), aligning with similar existing usage in the same module.

Changes:

  • Replaces five occurrences of manual Option<HashMap<...>> unwrapping with unwrap_or_default().
  • Removes unnecessary mut bindings where the metadata map is not mutated after initialization.
  • Keeps mut only where metadata is subsequently modified (e.g., adding "Content-Type" in invoke_actor).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mikeee
mikeee merged commit 783d315 into dapr:main Jun 15, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants