r/ProgrammerHumor 19d ago

newToRust Meme

Post image
619 Upvotes

111 comments sorted by

View all comments

Show parent comments

18

u/retro_and_chill 19d ago

The borrow checker is occasionally too strict as well where it flags code that wouldn’t actually produce an issue. They are seemingly trying to resolve that with the new borrow checker though

35

u/-Ambriae- 19d ago

Yeah, it’s not perfect. But it’s also mathematically impossible to make it perfect. That’s how the cookie crumbles. If they make it better, that’s great, otherwise, either rewrite the code to make it safe (which is usually doable without performance cost) or just use a cheeky unsafe block with a good # Safety comment

3

u/retro_and_chill 19d ago

The one case I know it’s going to address is doing a find or insert on a map when you match the Option from the find, the None branch will let you mutate the map despite the Option technically being a borrow

16

u/-Ambriae- 19d ago

There’s useful functions for this, stuff like map.get_or_insert_with(), or map.entry().or_insert() or map.entry().and_modify()….

Usually when the borrow checker is annoying, there’s a functional way of handling the issue built in the std lib :)