map_try_insert changes#155360
Conversation
|
|
This comment has been minimized.
This comment has been minimized.
9faa93f to
63ad76d
Compare
A PR to update https://github.com/rust-lang/hashbrown may be needed first to make |
|
Okay, I will keep this PR a draft for now. |
This comment has been minimized.
This comment has been minimized.
|
This is a test. It won't compile right now since I was using a local build of hashbrown. Let me know what you think. |
This comment has been minimized.
This comment has been minimized.
|
Originally I was thinking that I guess I'll re-nominate for @rust-lang/libs-api because there's a tradeoff here. Question: is there any interest in something like this as an alternative to putting the key in the pub struct OccupiedEntry<...> {
hash: u64,
elem: Bucket<(K, V)>,
table: &'a mut HashMap<K, V, S, A>,
original_key: Option<K>, // new field
}
impl<...> OccupiedEntry<...> {
fn original_key(&mut self) -> &mut Option<K>;
}The advantage is that users can get the unused owned @rustbot label +I-libs-api-nominated @malezjaa in the meantime feel free to open the HashBrown PR, and please add tests that the key is actually present when expected. |
|
Personally storing the key on It's true that |
|
I don't think that |
|
r? Amanieu Agreed that it's not very optimal to hold the key in the entry so I'll unnominate. |
42e6473 to
1971bcf
Compare
This comment has been minimized.
This comment has been minimized.
|
Maybe I should keep this as a draft until new version of hashbrown gets released? |
|
|
1971bcf to
ba68e6b
Compare
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
ba68e6b to
d04f60f
Compare
| /// assert_eq!(err.value, "b"); | ||
| /// ``` | ||
| #[unstable(feature = "map_try_insert", issue = "82766")] | ||
| pub fn try_insert(&mut self, key: K, value: V) -> Result<&mut V, OccupiedError<'_, K, V, A>> | ||
| where | ||
| K: Ord, | ||
| K: Ord + Clone, |
There was a problem hiding this comment.
Why did you add this?
There was a problem hiding this comment.
My bad, I messed up when rebasing.
96a8a4b to
46b7a36
Compare
|
Reminder, once the PR becomes ready for a review, use |
46b7a36 to
cee36c5
Compare
This comment has been minimized.
This comment has been minimized.
cee36c5 to
ca70543
Compare
View all comments
Made changes according to #82766 (comment).
r? @tgross35