Skip to main content

Rust

Why Rust

Greetings, fellow embedded enthusiasts! You’ve probably heard whispers about a new kid on the block - Rust. Now, you might be clutching your trusty C, thinking, “Is C dead? Should I start learning Rust? Why on earth should I rewrite my perfectly good C code in Rust?” These are all excellent questions, and fear not, we’re going to tackle each one in this article.

Welcome to another series of inpyjama blog posts. This series offers a practical introduction to Rust's core features. We'll prioritize code examples to illustrate how these features work. Occasionally, we'll bridge the gap by comparing Rust concepts to their counterparts in C.

Is C dead?

Absolutely not! Languages don’t just keel over and die, especially not when it’s the go-to language for nearly every embedded project and operating system out there. But is C perfect? Well, if you’ve ever found yourself wishing that C could be as easy to experiment with as Python, you’re not alone. Don’t get me wrong, I adore C. It’s my partner in crime for 90% of my daily tasks. It’s the ideal language for embedded systems, giving you the reins over memory and keeping bloatware at bay.

Should I start learning Rust?

Well, if you ask me, I'm a strong believer in continuous learning. I believe that whenever you get a job opportunity, you should grab it and learn as you go. However, there's another side to consider. How can you decide that Rust is not suitable for your project? If you want to make an educated decision about whether Rust is better than C for a project or not, you need to understand both languages. That means investing time in learning Rust so you can make an informed choice about the right tool for the job.

What about my legacy code?

So, you might be wondering, 'Should I rewrite my legacy code in Rust to integrate with my new project?' Well, I'd say that's a bit crazy! Rewriting all that C code would be a massive undertaking. Luckily, Rust understands this dilemma and provides something called a Foreign Function Interface (FFI). This lets Rust code work smoothly with functions written in other languages. We'll dive into the details of FFI in future articles.

Enter Rust

So, what’s the deal with Rust? Imagine a language that’s as speedy and compact as C and C++, but also ensures memory safety.

I like to think of Rust as a compelling combination of C and Python. It offers the lean, low-level efficiency of C while ensuring the memory safety and ease of use found in Python. While I could delve deeply into Rust's memory safety mechanisms, that would make this article far too lengthy. Instead, let's explore some of the lesser-discussed aspects of Rust that make it so appealing, qualities often overshadowed by its renowned safety benefits. We'll cover memory safety in depth throughout this series.

Let's shift the spotlight away from Rust's memory safety for a moment and talk about some of its underrated features.