A Month Of Rust
Background
A month ago, I decided to start learning Rust. I’ve been “Rust curious” for a while, and it’s been on my list to learn for some time now. It’s hard not to hear about Rust with all the “rewrites in Rust” happening.
With anything in life, it’s important for me to start with why. Why learn Rust?
I am not a PL person. I have always viewed programming languages as a means to an end. A tool. The first language that exposed me to programming was VBA. VBA showed me the power of programming and how it could automate many of the manual tasks I was doing in Excel.
From there, I learned Python because, from what I could tell, it was the de facto standard for beginners. I have since learned TypeScript and some C.
I have never really considered myself a “Python programmer” or a “TypeScript programmer”; programming to me is programming. All languages have loops, conditionals, variables, etc. I believe in choosing the right tool for the job and the same goes for programming languages.
With that said, I do see the benefits for those who are deeply invested in one particular language. They become masters of the language to the point where the language itself just disappears and it’s just the way they think.
Also, as someone who deeply cares about the quality of their work, it’s hard not to fall in love with your tools, especially one as important as a programming language. It is how you express and communicate your ideas. The language can even shape your way of thinking and how you approach a problem.
The most important things I look for in a programming language are: The values and the types of projects people are building with the language. For Rust, it says it right on the front page:
A language empowering everyone to build reliable and efficient software.
This is the type of software I want to be creating. Its values of performance and reliability resonate with me. You can also see it reflected in industry by the types of projects Rust is being used for, from databases and networking to operating systems and virtualization. The types of projects where performance and reliability matter.
Rust
For the past year, I have also been rounding out my computer science knowledge, learning C, Computer Architecture, Operating Systems and Networking.
As I was wrapping up my journey of filling in these computer science gaps, I felt it was finally time to scratch that Rust itch. So over the past month, I have made my way through the first 10 chapters of the Programming Rust book and 8 problems from 100 Exercises To Learn Rust.
I have found when reading the Programming Rust book, this is a book best read with your editor open to the side so you can type out the examples yourself (my repo). Also, the rust-analyzer is a must have to me.
Rust has great type inference, which means you often don’t have to explicitly write out the types, but rust-analyzer will provide inline type hints to show you the inferred type. A helpful exercise I will do is read an example in the book and make note of what I believe the type of each statement will be and then write up the example to see if it matches my expectations.
Having some C knowledge has proven to be helpful in learning Rust. Rust is trying to solve many of the problems (use-after-free, double free, dereferencing null pointers, out-of-bounds indexing) you would face with languages that require manual memory management, like C. Without running into those problems yourself, you might feel Rust is making you jump through many unnecessary hoops.
My first impression of Rust was that I was a bit surprised by how high-level this language felt for being a low-level systems language. With C, it always felt like such a hassle to do anything because you have to do so much yourself. It’s not just the language itself but everything around it as well.
Cargo is the main tool you use to manage your Rust projects. It has everything from running the Rust compiler, generating docs, running tests, and packaging your code. With C, not only do I have to learn C, but now I have to figure out what tool I want to use to build my project, what tool I want to use to format the code, and what library to use to test the code and so on. For Rust, all of that is already taken care of.
I would say the three major topics that have stood out to me so far are: the ownership model, enums, and error handling.
Ownership
If you have heard anything about Rust, it’s probably about its steep learning curve, mainly driven by the borrow checker, which is how Rust enforces its ownership model.

The main benefit you’ll hear you get from Rust is that it’s a memory-safe language. But how is this possible if Rust doesn’t make you manually manage memory or have a garbage collector? The Programming Rust book has a good section on these two approaches:
- The “Safety First” camp uses garbage collection to manage memory, automatically freeing objects when all reachable pointers to them are gone. This eliminates dangling pointers by simply keeping the objects around until there are no pointers to them left to dangle. Most modern languages fall in this camp from Python, JavaScript, and Ruby to languages like Java, C#, and Haskell. Relying on garbage collection means relinquishing control over exactly when objects get freed to the collector. In general, garbage collectors are surprising beasts, and understanding why memory wasn’t freed when you expected can be challenging.
- The “Control First” camp leaves you in charge of freeing memory. Your program’s memory consumption is entirely in your hands, but avoiding dangling pointers also becomes your concern. C and C++ are the only mainstream languages in this camp. This is great if you never make mistakes, but evidence suggests that eventually you will. Pointer misuse has been a common culprit in reported security problems for as long as that data has been collected.
But Rust takes a different approach and asks, “Why can’t we have both safety and performance?”

To do this, Rust uses this concept of ownership and borrowing. Now, in my own words, I would say Rust wants to ensure there is one owner of something (yes, I know you can have multiple owners with Rc and Arc). Now other variables can reference a value owned by something else. There are two types of references:
- a shared reference, which I personally think of as a read-only reference. You are allowed to have as many read-only references as you want. To get a shared reference to a value, you use
&, e.g.&ayields a shared reference toa’s value. - a mutable reference, which provides read and modify access to the value. No other references to that value may be “active” when you have a mutable reference.
The analogy I have in my head is similar to SQLite, where you can have multiple readers or one writer. Obviously, this analogy breaks down in many ways, but for now I think it’s an okay mental model to have.
My knowledge beyond this is limited. I put “active” in air quotes because that brings up the concept of lifetimes, which I am still learning about. For the most part, active to me is usually the lexical scope of the reference, but I don’t think this is entirely true. I also am still confused about when I would want to transfer ownership of something versus taking a reference to something.
One surprising thing to me when learning about ownership is once ownership is moved, that original owner is uninitialized, as if that variable was never defined. The Programming Rust book has an excellent diagram of this concept:
I am still struggling through writing code at the moment, often finding myself moving ownership inside a function when what I really wanted to do was take a reference. Luckily, I will say one amazing feature of Rust is the error messages. Here is an example:

You can tell a great deal of thought, care and effort went into these error messages.
Enums and Error Handling
I have used enums before Rust, but these aren’t your granddad’s enums. Rust enums are much more akin to what I know as discriminated unions in TypeScript. This is where you have one “kind” field that informs you what the rest of the type contains. An enum can only be one of its variants, and you have to first verify its kind so you know the type you have access to:
The same in Rust would be:
So the “kind” field is status in the TypeScript example, but in Rust, the kind is the name of the enum variant and is effectively built into the way you define enum types.
Now this is important because enums are everywhere in Rust. The two most common ones you’ll see are the Option<T> and Result<T, E> types, which is why enums and error handling go hand in hand.
These are both generic types, where type T can be any type and usually is inferred by Rust. So for Option, you either have None or Some(T). If you have a value that is an Option type, Rust will make you handle both cases: you have to check for None and Some(T) to be able to get access to the value in Some.
The same goes for the Result<T, E> type, but in this case we have an extra type parameter, E, so the error value can be a different type than the Ok value. In this case, we still only have two variants, and if you are dealing with a Result type, you once again have to handle both variants in your Rust code or else Rust will yell at you.
Rust has no concept of exceptions; instead, if your function can result in an error, you return the Result type. The only other thing you can do is panic. Panic is well-defined behavior, and Rust will either unwind the stack or abort the process.
I am still getting used to this way of writing code, but I have to say I can see why people like it so much. Especially with Rust’s support for pattern matching, it makes it very easy to match on each variant of the enum.
Rust also has some nice syntactic sugar like ?, which extracts the value from Some or Ok and lets execution continue. For None or Err, it returns early from the enclosing function, propagating the absence or error. It’s effectively shorthand for matching on both variants and either extracting the value or returning early.
Closing Thoughts
I have really only scratched the surface of Rust, but so far I am impressed. Many of the ideas in Rust aren’t necessarily new; algebraic data types and error handling have been around in other, mainly functional, programming languages for a while. Also, there was historical precedent around ownership and borrowing before Rust. What I actually appreciate, and what is novel about Rust to me, is how the creators have learned from its predecessors and were able to blend many of these features together in a cohesive and novel way.
I can see why Rust has cultivated this hype level. It’s safe, performant and comes with excellent tooling. It really seems you can have your cake and eat it too. But I don’t want to get ahead of myself. It’s clear that I am still in the honeymoon phase and we all know there are no silver bullets in software engineering, only tradeoffs.