LPGhatguy / thunderdome

Arena type inspired by generational-arena
Apache License 2.0
197 stars 15 forks source link

Implement Arena::get2_mut #22

Closed lynzrand closed 3 years ago

lynzrand commented 3 years ago

This PR adds Arena::get2_mut that returns mutable reference to two items of different indices at once.

This PR closes #21.


Well... there's definitely some code gymnastics inside to implementing this thing in safe Rust. Is there a better way to implement this, or maybe an unsafe implementation could be preferred?

lynzrand commented 3 years ago

I just implemented the unsafe version. It passed miri tests on my machine. Implementation notes are next to the code.


A quick note here:

According to lifetime elision rules, get2_mut(&mut self, Index, Index) -> (Option<&mut T>, Option<&mut T>) has the same lifetime as get2_mut(&'a mut self, Index, Index) -> (Option<&'a mut T>, Option<&'a mut T>). This means the function exports the expected lifetimes for references.


some random meme

LPGhatguy commented 3 years ago

Implementation is looking good, my comment is mostly a style nit.

Can you also add an entry to CHANGELOG.md that notes that Arena::get2_mut is an unreleased change? Thanks!

lynzrand commented 3 years ago

Added!

Ignore the force push please... That was just me trying to fix a style issue without wasting another commit and failed. I promise I won't do that the next time!

LPGhatguy commented 3 years ago

Thanks! :D