“You never wrote that test case, and so you never saw that the bug existed. So you just release your software, and then 10 years later you've got a car crashing into a wall, because suddenly that particular condition creates that bug. In Rust, you will not be able to release the software, because it will never compile. So unless you fix the bug, you don't have a software to release.”
sputnikintelligence.com
David is making the case for Rust's strictness in safety-critical firmware: it forces out bugs that no test ever exercised. This closes his long answer on ownership and strong typing in embedded code.
…about so he contacted me and we had some really interesting conversations around what could be done and about something later I've got I've got those 10 chapters done and I'm still kind of polishing things up a bit but yeah that's that's how we how we got we got to we got to that book in the end
…with C versus when you're working with Rust is there's particular bugs that that Rust can catch that C cannot besides obviously that you know the memory management things like that is there is there other things that make Rust a more valuable language for embedded development than compared to C?
Yes, so developing firmware in Rust sort of coerces you to follow some very strict rules in terms of how you're going to program, but also more importantly, how you're going to use resources. So you touched on memory management and there's also the aspect of ownership. So these are two pillars of Rust, right? Memory management and ownership of things, which is of course related. You also have this aspect of lifetimes as well. And in practice, what it means with Rust is that when you're going to try and access some hardware, if you do firmware development in Rust, there can only be one owner for a specific piece of hardware. So if you have inside a market controller, you have, let's say, a GPIO controller or you have a UART or something like this. When you are going to write your Rust code, and if you want to use that particular piece of hardware, you're going to have to take ownership. So you essentially have some kind of variable that represents the entirety of all the components that exist inside your microcontroller or microprocessor. And at some point, you're going to say, right, well, out of this big bundle of components that exist inside my microcontroller…
Now, in your book, you do do something which is quite important. I think people who are writing Rust don't always do, which is you need to build a no standard binary from scratch, right? What's actually involved with that? And why is that such a big deal that you need to make a very clear point…
So that's a really good question. So as I mentioned, the book is called Embedded Software with Rust. And there's always a heated discussion around what do you mean by embedded. And some people would say, embedded Linux is embedded programming. Or in my case, when I look at embedded, and I think a…
What about when you boot an application for embedded development with Rust versus C, is there something that's kind of different about it, or is it basically exactly the same? Now, the reason I ask that is because, you know, I had one of my first episodes, maybe even the first episode I ever did on…