Skip to content

Add methods to replace the key at a given index #405

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Aug 16, 2025

Maps and sets may fail if the new key/value is already present
elsewhere, but we know that's not the case for VacantEntry.

  • IndexMap::replace_index(&mut self, index: usize, key: K) -> Result<K, (usize, K)>
  • IndexSet::replace_index(&mut self, index: usize, value: T) -> Result<T, (usize, T)>
  • VacantEntry::replace_index(self, index: usize) -> (K, OccupiedEntry<'a, K, V>)

Resolves #404.

Maps and sets may fail if the new key/value is already present
elsewhere, but we know that's not the case for `VacantEntry`.

* `IndexMap::replace_index(&mut self, index: usize, key: K) -> Result<K, (usize, K)>`
* `IndexSet::replace_index(&mut self, index: usize, value: T) -> Result<T, (usize, T)>`
* `VacantEntry::replace_index(self, index: usize) -> (K, OccupiedEntry<'a, K, V>)`
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.

Feature request: IndexMap::replace_key
1 participant