indexmap-rs/indexmap

Implement a `replace_full` method on `IndexSet`

Closed this issue · 3 comments

Hello! I was wondering whether it would be possible to implement a replace_full method on IndexSet? Similarly to how there are the insert and insert_full methods, I think it might also be useful to also have a replace_full method.

pub fn replace_full(&mut self, value: T) -> (usize, Option<T>)

I believe the semantics would be:

  • If the item already exists, replace it with value and return its index (which will remain unchanged) as well as its old value.
  • Otherwise, insert the item into the set and return its index as well as None.

Do you mean on IndexSet? If so, that makes sense to me.

Do you mean on IndexSet?

Yes, I do 😅 Sorry, I've updated the issue!

I went ahead and created #222 with a possible implementation, I hope that's okay 🙂