Rust is an emerging systems programming language that’s mostly used for memory management, safety, and performance. It’s a statically typed programming language like Java, C, and C++, where variable types are known at compile time, and it’s designed for performance and safety, especially safe concurrency and memory management. Rust’s low-level control and memory safety make it a good choice for embedded systems development, but it’s being used in a much wider array of applications.
Rust is an open-source project developed originally at Mozilla Research and uses a syntax like C++. Beginning in 2021, the Rust Foundation took on responsibility for Rust and is managing the development of the language. Rust is being used in a wide range of applications like operating systems, web services, interpreters, virtual machines, mail servers, databases, and gaming (Figure 1), some of which are detailed more below.
Rust application examples
Device drivers — Low-level control and memory safety make Rust suitable for developing device drivers. The development of safe and efficient drivers that can work consistently with the associated hardware is simplified by Rust’s type system and borrow checker.
Web development — Rust’s scalability and safety, plus its async/await support, simplifies the development of backend web services with high levels of concurrency. Its efficient memory management and safety enable developers to write memory-safe web applications.
Machine learning (ML) — Rust is not a mainline environment for ML projects, but that may change since the language includes libraries like rusty-machine and tch-rs that can support the development of ML models and tools.
Operating systems (OS) — Rust provides low-level control, efficiency, and memory safety that make it attractive for OS developers. Rust simplifies the development of secure OSs. Examples of OSs built using Rust include Mozilla, intermezzOS, QuiltOS, Rux, and Redox.
What’s a borrow checker?
In most other languages, programmers aren’t concerned with where variables are stored; the garbage collector takes care of variable storage and memory. In Rust, the borrow checker replaces the function of the garbage collector.
The borrow checker is Rust’s way of enforcing its borrowing and ownership rules, which are designed to prevent data races at compile time. It’s a safety feature that ensures references to data don’t outlive the data they refer to. In addition to preventing data races, the borrow checker prevents null or dangling pointer dereferences and double-free errors.
Concurrency — Rust supports zero-cost abstractions that don’t incur additional runtime overhead compared to writing the code out manually and safe concurrency and multi-threading. The built-in async/await syntax and the types of systems help prevent common concurrency bugs.
Memory safety — Rust’s ownership and borrowing system helps prevent common memory-related bugs like buffer overflow. The ownership and borrowing system guarantee memory safety at compile time.
Performance — Rust delivers the same high-performance level measures as C and C++, plus strong concurrency and memory safety support.
Readable syntax — Rust’s syntax is designed to be more readable compared with C and C++. It includes features like functional programming constructs, pattern matching, and type inference that can simplify writing and maintaining code.
Cargo — Cargo is Rust’s package manager and builds the system. It’s included in the Rust distribution and automates building, testing, and publishing new projects.
Rust has room to grow
Compared with C and C++, Rust is an emerging language with an evolving development ecosystem. That presents challenges and opportunities for growth. Rust is new and has a relatively steep learning curve. Rust has a smaller developer community and few libraries, resources, and tools available. The language’s type system and borrow checker can mean longer compilation times compared to C and C++. Rust’s safety features can be a minus as well as a plus for developers. The safety features can limit low-level control and make it difficult to implement some low-level optimizations and directly interact with hardware. Despite its many challenges, Rust is still well-suited to embedded development projects, especially those that benefit from high levels of safety, reliability, and security.
As a relatively young language, Rust has grown quickly in popularity. It provides developers of embedded systems and a range of other applications with a new choice beyond C and C++ that can support concurrency, memory safety, and high performance. Tools and libraries for more advanced uses like ML are just beginning to appear. Rust is worth watching, and its use is expected to continue growing.
Rust Language Organization
Rust + Embedded: A Development Power Duo, Espressif Systems
What is Rust Programming Language?: A Guide to This Evolving Language, Litslink
Why is Rust programming language so popular?, Codilime