-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add get_mut_or_insert #151
Conversation
There is a version of |
Maybe a better name would be |
@Yosi-Hezi do you want to rebase onto master now that #150 has been merged? My personal inclination would be for |
d6f4a39
to
749ded4
Compare
@jeromefroe rebased |
src/lib.rs
Outdated
/// assert_eq!(cache.get_or_insert_mut(3, ||"f"), &mut "f"); | ||
/// assert_eq!(cache.get_or_insert_mut(3, ||"e"), &mut "f"); | ||
/// ``` | ||
pub fn get_or_insert_mut<'a, F>(&mut self, k: K, f: F) -> &'a mut V |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn get_or_insert_mut<'a, F>(&mut self, k: K, f: F) -> &'a mut V | |
pub fn get_or_insert_mut<'a, F>(&'a mut self, k: K, f: F) -> &'a mut V |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matklad fixed.
Thanks for the PR @Yosi-Hezi! |
This PR adds the
get_mut_or_insert
method, which is based onget_or_insert
but returns a mutable reference instead of an immutable reference.Relevant open issue: #30