Closed lynzrand closed 3 years ago
I would accept a PR for Arena::get2_mut
. I think the more generalized form gets into hairy situations pretty easily, and we ought to be able to implement get2_mut
with only safe code using slice::split_first_mut.
As one coming from
generational-arena
, I foundthunderdome
is lacking a method similar toArena::get2_mut(&mut self, Index, Index) -> (Option<&mut Value>, Option<&mut Value>)
.This method allows library users to access two different values at once (as long as their indices are different), allowing one to perform complex operations efficiently. An example usage would be connecting doubly-linked lists inside this arena, where having mutable references of both lists' ends simplifies the code.
Taking this idea one step further, adding another method like
unsafe Arena::get_many_mut(&mut self, impl Iterator<Item=Index>) -> impl Iterator<Option<&mut Value>>
(where the user ensures no two indices are the same) also seems reasonable. I'm just not sure if it's really needed.