May I add yet another borrow checker puzzle to the many threads dedicated to borrowed values that don't live enough (I've read several without finding one that applied to my case.)
I would like to understand the compiler's reasoning for get_mut() though. What was it trying to tell me? Why did it believe the borrowed value didn't live long enough when it syntactically appeared as though the Ok() expression was the expression returned from the function?
Also, it seems that into_mut - if I found it correctly - is unsafe. Why does this require an unsafe operation?
get_mut() borrows from the entry itself but the entry dies after the match block. into_mut() moves exclusive ownership of the underlying reference to the caller, and consumes the entry, thus upholding borrow rules.
As for this part, yes, I think you found the right place.
The unsafe is needed because pair() returns a *mut (K, V) and this code derefs that ptr. If I understand the surrounding code and comments correctly, the raw ptr is used for performance reasons - they represent the array of key/value entries using a raw ptr + offset calculation. This representation is used both for full (occupied) and empty (vacant) slots. The comments allude to this being more efficient than the naive alternative of a Vec<Option<(K, V)>> representation.