Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageMap insert entry if key has not had a value set #5147

Closed
Braqzen opened this issue Sep 26, 2023 · 0 comments · Fixed by #5441
Closed

StorageMap insert entry if key has not had a value set #5147

Braqzen opened this issue Sep 26, 2023 · 0 comments · Fixed by #5441
Labels
enhancement New feature or request good first issue Good for newcomers lib: std Standard library

Comments

@Braqzen
Copy link
Contributor

Braqzen commented Sep 26, 2023

Rust has the following map.entry("").or_insert();

It would improve UX if we had a try_insert() or insert_if_empty() method which checks if a value has been set for a key and if it has not then it inserts it.
This removes the need for higher level code to manually check if there is an entry and then insert it via another line of code if it has not been set (removing the need for an if expression at a high level)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers lib: std Standard library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant