Ownership & Borrowing in Rust

Brandon Wofford
16 min readFeb 22, 2024

It’s become a bit of a cliché for developers by now, but I’ve fallen in love with Rust. Being self-taught, I’ve dabbled in a bunch of languages like C#, Python, JS, Go, and so on, mostly sticking to the comfort zone of garbage-collected languages. However, I’ve always been a bit jealous of the raw performance that lower-level systems languages offer, but the horror stories about all the “foot-guns” with C++ (memory leaks, dangling pointers, buffer overflows) always kept me at bay. Plus, there’s no ignoring the big security red flags — like that time in 2019 when Microsoft mentioned nearly 70% of their security issues were due to memory management, a sentiment echoed by Google’s Chrome team.

After I built a local DNS server in Go, I started thinking it might be fun to squeeze more performance out of it, and that nudged me towards finally giving a systems language a shot. That’s how I ended up diving into Rust. The syntax threw me for a loop at first, but thanks to the compiler’s guidance, I got the hang of it pretty quickly. What stood out to me was how many of the classic systems programming pitfalls just… weren’t issues. No manual memory deallocation headaches, no hunting for null pointer references, nothing. Sure, my Rust DNS server project is more of a learning experiment than anything (incomplete and barely functional), but I didn’t run into any of those notorious problems I’d been warned about. That’s largely because Rust is designed to sidestep those issues or make them really hard to stumble into.

This segues neatly into one of Rust’s most innovative features: its borrowing system. The borrowing system is Rust’s answer to ensuring memory safety without the overhead of garbage collection, effectively closing the door on a whole class of bugs that plague systems programming. This system, coupled with Rust’s ownership model, means that many of the common errors I was worried about are caught during compile time, not after I’ve already shipped the code. It’s a game-changer, really, making Rust not just a safer choice for systems programming, but also an incredibly efficient one.

What Is Ownership?