Is there a reason there's no get_disjoint_mut for BTreeMap?

I ran into a case today where it would be nice to be able to get mutable references to multiple of the values stored in a BTreeMap. I notice that get_disjoint_mut exists on slice and also exists on HashMap.

I don't know much about the specific internals of BTreeMap, is there a reason why a get_disjoint_mut cannot be easily implemented for it?

1 Like

I'd assume the reason is more that no one got around to proposing it or implementing it yet. I see no reason it could not be implemented.

1 Like

BTreeMap is complicated so it won't be easy to implement.

But it should be possible and seems useful indeed.

3 Likes

I've created this ACP proposing the get_disjoint_mut and get_disjoint_unchecked_mut methods be added to BTreeMap. Add a `get_disjoint_mut` method to `BTreeMap` · Issue #896 · rust-lang/libs-team · GitHub