Skip to content
New issue

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

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

Already on GitHub? # to your account

add swap method to the Map trait #5392

Closed
thestinger opened this issue Mar 15, 2013 · 3 comments
Closed

add swap method to the Map trait #5392

thestinger opened this issue Mar 15, 2013 · 3 comments

Comments

@thestinger
Copy link
Contributor

Like insert, but returning the value that was replaced if applicable.

@ghost ghost assigned thestinger Mar 15, 2013
@14427
Copy link
Contributor

14427 commented Mar 19, 2013

A function along the lines of fn update(&mut self, key: K, f: fn(V)->V) to mutate a value in place would also be helpful

@thestinger
Copy link
Contributor Author

@14427: #5528 adds a find_mut method which is quite similar

bors added a commit that referenced this issue May 7, 2013
Closes #5392 and #5393

I implemented the pop/swap methods for TrieMap/TreeMap/SmallIntMap, and I also updated all of them such that pop isn't just a remove/insert, but rather it's all done in one operation.

One thing I did notice is that with default methods it'd be really nice to define `insert` and `remove` in terms of `pop` and `swap` (or vice versa, just to have them available).
@alexcrichton
Copy link
Member

Closed in #6236

@thestinger thestinger removed their assignment Jun 16, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue May 2, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants