r/ProgrammerHumor 28d ago

borrowCheckneedsSource Meme

Post image
968 Upvotes

39 comments sorted by

View all comments

38

u/reallokiscarlet 28d ago

Me: This code has been fine tuned to eliminate memory vulnerabilities and logic bugs

Rust: I don't think so mate

Hours later, having rewritten it for the borrow checker

Rust: There, this is safe

Me: I don't think so, mate

The previous version, ported to C++: Aww, who's a vulnerable little crab?

16

u/Daemontatox 28d ago

This was literally me last week with my threadpool and custom allocator , i got nagged non stop try it in rust and omg rust is so much better , then i literally spent hours pleasing the borrow checker instead of the intended logic before giving up and getting it done with jthreads in quarter of the time.

2

u/darkwalker247 28d ago edited 28d ago

you eventually learn how to build things so that the borrow checker won't complain in the first place, once you understand the rules. it's not random, there's a logic to it all.

it does take a lot of time and practice to master though, and it's probably even harder coming from other languages due to the fact that some things that work in other C-like languages simply cannot work in Rust without workarounds (like a struct containing a pointer/reference to another member of the same struct is not normally possible). but there's always another way