feature article
Subscribe Now

Rust Rules! (Programming Language-Wise)

Have you heard tell of the Rust programming language and how it is growing to be a serious contender in embedded space (where no one can hear you scream)? If not, then make yourself comfortable, “O my Best Beloved,” and I shall babble, blabber, and blather on this topic, as is my wont, but first…

If you are a non-programmer (or even if you are a programmer, now that I come to think about it), when you hear the word “rust” spoken in a conversation, your knee-jerk reaction is probably to think about the corrosion that occurs when iron or iron-containing metals are exposed to oxygen and water.

In a crunchy nutshell: (a) the iron loses electrons (iron atoms in the metal lose electrons to oxygen molecules in the air), (b) the oxygen gains electrons (oxygen molecules absorb the electrons, becoming more negatively charged), (c) water accelerates the process (water molecules help move electrons from the iron to the oxygen), and (d) iron oxide forms (the iron and oxygen combine to form iron oxide (Fe2O3), which is what we commoners call rust).

On the downside, rust provides a good example of a natural process that increases entropy; that is, the disorder or randomness of a system. Rust serves as a reminder that the universe itself is moving toward “heat death.” This will be a state of maximum entropy in which all energy is evenly distributed, and no useful work can be done. Galaxies will drift apart, stars will burn out, and all will become cold, still, and uniform. “A final, rusted-out husk of what once was,” one might say.

I don’t know why, but I suddenly find myself feeling a mite maudlin and mawkish. On the upside (and I’m grabbing at straws here), rust can be pretty. 

Whilst destructive, rust can also be pretty (Source: Pixabay.com)

And now I find myself transitioning into a poetic pose (it’s been a funny old day). For example, we could summarize where we find ourselves thus far in this column as follows (I welcome any additional or alternative contributions you might care to offer in this vein):

         Rust devours yet decorates,

         It corrodes yet creates,

         In its ruin, there is art.

Now my mind is really racing. Have you read The Story of Earth: The First 4.5 Billion Years, from Stardust to Living Planet by Robert M. Hazen? If not, then I would class this as a “must read.” This thought-provoking tome opened my mind to all sorts of concepts.

For example… the Earth is composed of elements, compounds, and minerals. An element is a basic substance made up of only one type of atom. A compound is a substance—like water—that is formed when two or more elements chemically bond together in a fixed ratio. A mineral is a special form of compound in the form of a naturally occurring, inorganic solid with a definite chemical composition and a crystalline structure. Some minerals are formed from a mixture of different compounds. Everything in this paragraph is a gross simplification (except for this sentence, which is 100% on point).

The International Mineralogical Association currently recognizes around 6,000 mineral species here on Earth. However, when the Earth originally formed approximately 4.5 billion years ago, in addition to elements like iron, oxygen, silicon, aluminum, calcium, and carbon, it also contained around only a dozen “proto-minerals” or “ur-minerals.” These are the earliest crystalline solids that formed before planets even existed. They developed in extreme environments such as supernova ejecta, stellar atmospheres, and interstellar dust clouds.

So, how did the Earth go from containing only a dozen proto-minerals to the 6,000 species we see today? This is where things start to boggle the mind. In his book, Robert introduces the concept of “mineral evolution,” describing how the diversity of minerals increased dramatically over time due to processes like planetary differentiation, tectonics, and the influence of life (it’s this latter item that’s the real kicker).

As I’ve mentioned in previous columns, in Dirk Gently’s Holistic Detective Agency by Douglas Adams, the eponymous Dirk is an unconventional detective who believes in the “fundamental interconnectedness of all things.” The idea is that everything in the universe is interrelated, meaning that even seemingly random events or trivial details can have a meaningful connection.

Well, it turns out that the mineralogical and biological histories of Earth are deeply and richly interconnected (Douglas Adams would be proud). Minerals provide the essential building blocks for life by forming the structures and environments in which life can thrive. Life, in turn, shapes the mineral world through biological processes like metabolism. Together, they create a dynamic interplay that continues to shape Earth’s geology and biosphere.

“But what’s this got to do with rust in any of its incarnations?” I hear you cry. I was worried that you weren’t going to ask. A transformative period in Earth’s history occurred 2.4 billion years ago. Known as the Great Oxidation Event (GOE), this was caused by early photosynthetic microbes, such as cyanobacteria, which started producing oxygen as a byproduct of photosynthesis.

Prior to the GOE, there was a lot of raw, elemental iron, both on land and dissolved in the oceans.  As oxygen started to accumulate in the atmosphere, it reacted with exposed iron-rich rocks on land, leading to the formation of red iron oxide minerals. Also, as oxygen started to dissolve into the oceans, it reacted with the dissolved iron. The resulting iron oxides, which were insoluble in water, settled to the ocean floor, creating banded iron formations (BIFs).

Ashes to ashes, rust to rust (Source: Pixabay.com)

Bearing in mind all that we’ve discussed thus far, I hope you can understand my confusion when I was informed that I should have a chat with Florian Gilcher from Ferrous Systems regarding their latest Rust-related announcement. I mean, I like rust as much as the next bipedal lifeform but—previous discussions notwithstanding—I don’t obsess about it… well, I try not to obsess about it… well, not every day.

It turns out that the folks at Ferrous Systems are Rust Experts—that is, they know everything there is to be known about the Rust programming language, tools, technologies, and applications. Based on this, they offer a smorgasbord of Rust-related services, from training to consulting and from library creation and evaluation to code review and optimization.

Ferrous Systems was founded in 2018, but Florian has been a “Rustacean” since 2013, which is a couple of years before Rust 1.0 was officially launched in 2015. The company currently counts 25 employees, and this number is increasing rapidly, concurrent with the increasing uptake of Rust. Florian is co-founder, CTO, and CEO, while his brother, Felix, is co-founder, CEO, and CTO (and I thought my life was complicated).

Florien says that the 10-year anniversary of the launch will be in May 2025. Apparently, there’s going to be a huge party in the Netherlands (I wonder if I’ll be invited… “I don’t have a thing to wear!”).

How many different programming languages are there in the world? I’m going to go out on a limb and say “lots” (and you can quote me on this). I’ve seen estimates of anywhere between 2,000 and 8,000 (see also the List of Programming Languages on the Wikipedia).

So, does the world really need one more? Well, according to the proponents of Rust, the answer is a resounding “Yes!” Many programmers like C/C++ because they provide low-level control (great for embedded applications) and they span the gamut from edge (microcontroller) to cloud (server). On the other hand, it’s also easy to… let’s say “mess things up” with these languages (I have the book C Traps and Pitfalls by Andrew Koenig sitting on my desk looking balefully at me as we speak).

Like C/C++, Rust also provides low-level control and spans the microcontroller to server application domains, and it’s claimed to be “blazingly fast and memory-efficient.” Unlike C/C++, Rust’s rich type system and ownership model are claimed to “guarantee memory-safety and thread-safety.” Also, unlike Python, which requires us to use MicroPython on microcontrollers, Rust is Rust wherever you find it.

Florian tells me that one reason for the exploding interest in, and deployment of, Rust-based applications is the language’s strengths with respect to things like Functional Safety (FuSa) and cryptographic attack (by which I mean defending against such an attack, not mounting one).

IEC 62304 is an international standard that defines the life cycle requirements for medical device software. The real reason Florian wanted to chat with me was to bring me up to date with the fact that Ferrous Systems, which has carved out a leadership role with respect to Rust solutions for safety-critical systems, recently announced that its flagship tool chain, Ferrocene, has achieved IEC 62304 Class C qualification for medical device software. This milestone positions Ferrocene as an ideal solution for medical device developers wanting to streamline compliance efforts while ensuring the highest standards of safety and reliability.

Florian was also eager to share a couple of cool real-world Rust-based applications—both hobby and professional—to demonstrate the deployment versatility of the language. Florian says that these projects are all “active and not just code dumps.”

The first is Neotron, which is a hobby project created by Jonathan Pallant, who is Ferrous Systems’ lead embedded engineer and trainer. As Florien says, “Imagine an 80’s home computer… but implemented on a modern microprocessor. It’s a bit like MS-DOS, but on a Cortex-M.”

Next, we have Servo, which was the original Rust project. This is a full browser engine, completely written in Rust. Also, we have sudo-rs, which is a port of the classic program “sudo” to memory-safe Rust. This was created as a collaboration between Ferrous Systems and another embedded company called Tweedegolf.

Espressif has a development board called ESP32-C3-DevKit-RUST-1 that is fully supported by Rust from the vendor side. Then there’s RTIC, which is a hardware accelerated Rust real-time operating system (RTOS). Also, the Rust Embedded Devices Group is busy making sure embedded devices are well supported. 

If graphical user interfaces (GUIs) float your boat, then Slint is a Rust-based project of ex-QT engineers that is blazingly fast, and that targets embedded devices first and foremost. It reaches 60fps even on very small devices.

Last, but certainly not least (and remember these are just a few examples with which to tempt us), we have TockOS, which is an embedded operating system (OS) fully built in Rust that provides memory isolation on chips without an MMU. There’s also a safety-critical variant called OxidOS. 

The C programming language was created in 1972. The first version of C++ was released in 1983. Python bid the world a cheery hello in 1991, and Java made its first formal appearance in 1995. These languages are constantly jockeying for position as to the number of their users. I think the current ranking is Python on top, followed by C, C++, and Java, but that was at breakfast this morning—I can’t say who will be ruling the roost by teatime. 

The point is that Rust is a relative newcomer, appearing on the scene just 10 years ago as I pen these words, which was two decades after Java, and yet Rust already has millions of users, with more boarding the Rust train every day.

I don’t know about you, but I think this all sounds jolly exciting. However, it’s not all about me (it should be, but it’s not), so what do you think about all this?

8 thoughts on “Rust Rules! (Programming Language-Wise)”

  1. Do I have to use a different compiler for each different ISA? I think “yes” and that means that first I must find a RUST compiler for RISCV and each different ARM ISA.

    1. Rust is relatively tightly coupled with LLVM which is generally pretty straight forward for supported targets. Embedded use and support tends to vary a lot outside that.

      https://rust-embedded.org/

      Is your best starting point. That said you should get some pretty reasonable code reuse.

      1. Thanks.
        That is almost the same as having a different compiler. Also I am guessing support for plain old C?
        C# has recently added conditional assignments which eliminates a lot of if/else/branch statements.

        So now we have a programming language source syntax that closely resembles the logic expressions used by hardware designers. Also C# expression evaluation is stack based rather than having to do register assignments and load/store operations.

        For a couple of hundred LUTs and 3 embedded dual port memories an FPGA can do in a few hundred clock periods what a CPU takes thousands.

  2. Time for a bucket of cold water maybe?
    I thought Rust was a good language when I first looked at it some years ago and it certainly has gained some traction, but….
    MODCARGO_CRATES anyones!!! Take a look at the infrastructure overheads involved!
    It certainly tidies up a lot of things that were/are confusing with C/C++ but maintenance is not trivial.
    Love the iron oxide preamble.
    I also agree with and second Karl’s comment.

    1. C# is opensource, has conditional assignments that are more user friendly than using C if/else for conditions.

      Since I am a logic designer,my preference is to design rather than us an embedded processor with all
      the levels of cache, DDR, etc.

      At the lowest level, the C language requires a control program to handle the include library functions.
      and the list goes on. i.e. cache coherence may or may not work according to other articles by Max.

      And no one seems to realize that loads and stores are the biggest limitation to performance. Or maybe they blindly accept that multi-level caches are the answer.

      Meanwhile there are unused embedded block memories that could be used for working storage and eliminate the cache nonsense.

      and the block memories have true dual port mode so two operands can be reaad during the same cycle that a result is written.

  3. Hi Karl and Red (and Red and Karl — no favorites here) — I’m going to ask the folks from Ferrous Systems to chime in here — in the meantime, what did you think to my wafflings about rust in the context of Earth’s evolution (as opposed to the evolution of the Rust programming language on Earth)?

  4. Hi Max, Chris Packham is a naturalist and wildlife advocate and presenter with the BBC. He presented a series some while ago that went through some of the things that you mention from the very early days (geologically speaking) to discussing how humans have affected the planetary ecosystem. What I find truly bind boggling is the scale of these changes that you mention. Cyanobacteria are teeny-weeny organisms yet there are gigatonnes of oxygen and other biologically active gases in the atmosphere. Geological timescales are simply staggering. I have a book on loan from my sister called Deep Time which like Hazen’s book looks to be an interesting read – I have only just started reading it but I intend to seek out Hazen’s book – thanks for the recommendation. As ever, an interesting article – I would expect no less from you!!

    1. Hi RedBarnDesigner — I can’t wait to hear what you think about “The Story of Earth” by Hazen. It’s one of my favorites. A couple of others I always recommend are “The Disappearing Spoon” by Sam Keen, “Wetware: A Computer in Every Living Cell” by Dennis Bray, and “Life’s Ratchet: How Molecular Machines Extract Order from Chaos” by Peter M Hoffmann

Leave a Reply

featured blogs
Feb 19, 2025
Silicon Labs is expanding our portfolio as the industry-leading supplier of energy harvesting and power-optimized solutions for IoT....
Feb 20, 2025
Logarithmic gears, hyperboloidal gears, double helical bevel gears, elliptical gears, hypoid gears, helicon gears, spiroid gears, and more....

featured chalk talk

Advantech Dual Band WiFi
Sponsored by Mouser Electronics and Advantech
In this episode of Chalk Talk, Amelia Dalton and Monica Goode from Advantech investigate the what, where, and how of dual band WiFi. They also explore the benefits that dual band WiFi can bring to a variety of embedded designs and how you can take advantage of Advantech dual band WiFi solutions for your next design.
Jul 31, 2024
84,023 views