Skip to content

Add try_get_or_insert() method #171

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

Merged
merged 2 commits into from
Jun 30, 2023
Merged

Conversation

redforks
Copy link
Contributor

If key not cached, and the FnOnce need return Result<>, get_or_insert() method will hard to use, I dive into a few
LruCache Dependents crates, they query the cache first, if not exist in cache, generate the value (possible Err), then
save the result into cache. Requires two hash op, and make the code logic a bit complex.

Copy link
Owner

@jeromefroe jeromefroe left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @redforks, this looks great! Before merging, mind adding a test for the new function?

@redforks
Copy link
Contributor Author

There is a doc-test, I though that is enough. I'll add a unit-test later, thanks for review my commit

@redforks
Copy link
Contributor Author

Added unit test for try_get_or_insert() method

@jeromefroe
Copy link
Owner

@redforks sorry for the delay getting back to this, everything looks good to me, CI is just failing because of formatting. I'm going to merge this pull request as-is and fix the formatting issue in a follow up PR.

@jeromefroe jeromefroe merged commit dbbf20c into jeromefroe:master Jun 30, 2023
@jeromefroe jeromefroe mentioned this pull request Jun 30, 2023
@redforks
Copy link
Contributor Author

Thanks, I'll pay attension to the code format next time

@jeromefroe
Copy link
Owner

Thanks, I'll pay attension to the code format next time

No worries!

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.

2 participants