Rust

About Rust

Rust is a programming language for writing low-level, high performance code. It prioritises safety and developer experience without sacrificing performance. In particular, it is memory safe (like Java, Python, and other high-level, memory-managed languages) but has performance and low-level control similar to C or C++. Rust has a powerful type system which guarantees memory safety and facilitates writing correct-by-design software.

Contents

Rust is open source and has a strong, supportive community. Rust is widely used across the industry, wherever performance and security are priorities. It is used by startups and industry giants (Google, Microsoft, Meta, Huawei, and many more), and across multiple domains (cloud infrastructure, database implementation, web back-end, ...).

Rust 1.0 was released in 2015 and it has been growing steadily as a language and in usage ever since. It is a mature and stable language. Due to the community's emphasis on backwards compatibility, there have been effectively no breaking changes in more than nine years and over 80 releases.

There are downsides: Rust is a big language which doesn't hide the underlying complexity of low-level programming. The learning curve can be steep and sometimes frustrating. If you don't need high performance or low-level control, using a higher-level, managed language is usually a better idea. Integration with some tools (especially bespoke or proprietary ones) can be challenging (although integration with many open source tools or those which use the C ABI or LLVM as an interface is generally good).

Rust interoperates with other languages and can be adopted incrementally. Organisations can leverage its benefits by using it in areas where security and performance are the highest priority. Adopting a new language takes time: integration with existing code and tooling, upskilling teams, and adjusting processes all take time. However in the long-run, adopting Rust can be a massive productivity boost thanks to fewer bugs (especially hard-to-debug memory safety issues), excellent developer experience, and happier developers.

Memory safety

Memory safety bugs are typically hard to find, hard to debug, and are often security vulnerabilities. There is widespread acknowledgement, from big tech companies (e.g., Microsoft and Google) to the Whitehouse and Department of Defense, that software should be built in memory-safe languages.

Companies are adopting Rust for its ability to write high performance, low-level code without losing the benefits of memory safety. Currently, this is a unique advantage. Without Rust, engineers have to make a trade-off between performance and low-level control (using C, C++, assembly language, etc.) or memory safety (using high-level languages). Despite advances in static analysis, best practices, and developer tools, there is no way to guarantee C or C++ code is free from memory safety bugs. Even with industry-leading tools and practices, such bugs are common and severe. Some high-level languages offer excellent performance in some scenarios, and if these can satisfy your requirements, they are a good option. However, they cannot offer the low-level control and guaranteed, consistent low latency and high performance which are offered by systems languages such as C, C++, or Rust.

Rust logo

Rust's safety philosophy extends beyond memory safety. Rust has strong, static type checking, a powerful type system, and rich data types, which enable correct-by-design programming. The language prevents common errors such as out of bounds access of arrays, integer overflow, and many memory leaks. The standard libraries continue this approach: using RAII to ensure mutexes are locked and unlocked correctly, bounds-checking access to collections, and preventing iterator invalidation. Importantly, Rust's safety guarantees apply even in the presence of concurrency, and Rust ensures that concurrent programs are data race free.

To learn more about memory safety, and why memory unsafe languages are dangerous, read this excellent article.

Performance and low-level control

Rust is used to write the world's most performance-critical systems. Like C/C++ and unlike most high-level languages, Rust has effectively no runtime and no garbage collector. That means minimal runtime overheads and no pauses due to garbage collection. Rust has a design philosophy of 'zero-cost abstractions' which applies to all features in the language. This concept means that a feature has the same or better performance as a hand-coded version, and that if you don't use the feature it has no overhead at all. These aspects of Rust combine to guarantee predictable and consistent performance, and extremely fast code.

Low-level control over memory and CPU usage means that there is opportunity to optimise code down to the lowest levels. Rust uses LLVM (the technology behind the Clang compiler for C/C++) which brings some of the best possible compiler optimisation to Rust.

Powerful, safe features for concurrent and asynchronous programming mean that Rust programs scale well on modern, highly-parallel processors and efficiently make use of resources. You can write concurrent and parallel code with minimal overheads and much reduced fear of subtle, difficult to reproduce bugs.

Rust has no runtime, and uses standard operating system features such as threads and memory allocation. There is no garbage collection and no overheads such as universal vtables or managed stacks. Rust offers precise control over the layout of data in memory as well as where in memory that data lives (stack vs heap, and precise control of the allocation mechanism). Put together, this means that when you need absolute control over every byte and every CPU cycle, you can have it.

This philosophy of low-level control extends to the standard library and ecosystem. Libraries for IO, locking, and so forth stick close to the underlying operating system primitives, with many options for configuration. Similarly, libraries in the ecosystem usually offer low-level APIs as well as more abstract ones.

If you need to work in environments without an operating system, such as embedded computing, writing your own OS, or doing very low-level work, Rust supports that too. Rust can work in highly constrained environments with very limited memory or without a heap.

Interoperability

One of Rust's key advantages is that it interoperates smoothly with other languages. It can use the C ABI for functions and data structures which means that bidirectional interop with C or C++ is overhead-free and transparent (with modern toolchains, compiler optimisations can even happen across the language boundary). Because Rust uses standard OS facilities and has no runtime of its own, interop works in multi-threaded programs too.

Since the C ABI is the lingua franca of programming languages, and because of the low-level control Rust offers, Rust interoperates well with many high-level languages too. Projects exist for working with Python, Javascript, Ruby, Java, and many more. Rust also has excellent support for targetting WebAssembly.

Tools for linking, debugging, monitoring, etc. can often work with Rust with little modification and across language boundaries. Again, because Rust compiles down to machine code and uses standard forms of libraries, debug information, etc.

Productivity

Presentation at Rust Nation UK. Slide reads: 'Rust teams at Google are as productive as ones using Go, and more than twice as productive as teams using C++.'

Lars Bergstrom, director of engineering at Google, presenting at Rust Nation UK, 2024.

Rust offers expressive abstractions and data-types, and strong typing. These allow for correct-by-design programming patterns, fewer runtime bugs, and writing complex programs safe in the knowledge that the compiler will help enforce the programmer's intended invariants.

Rust's standard library is extensive, but deep rather than wide. Together with a thriving ecosystem of high-quality libraries and an open-source culture, Rust programmers have the library code they need to work effectively and productively. Rust's community is friendly and supportive, and there is a huge volume of resources available online for learning new techniques or APIs.

Rust also has great tool support. There are several IDEs with well-developed Rust support, including Visual Studio Code and Rust Rover from JetBrains. Rust ships with tools for formatting, linting, documentation, and packaging. Thanks in part to the fact that Rust targets machine code rather than a virtual machine, Rust code can be debugged and profiled using many standard tools (e.g., GDB, LLDB, perf, or Visual Studio). Porting tools which work with C/C++ code is generally straightforward.

Adoption

Rust 1.0 was released in 2015, and Rust has demonstrated stability, maturity, and staying power. Rust usage is growing strongly (it was the fastest growing language on GitHub in 2023, and second fastest in 2022), and Rust is widely liked by developers (it has been voted 'most admired' or most loved' in the StackOverflow developer survey every year for the past eight years).

Rust is well-known for its friendly and helpful community. As well as being a source of help and support, the community maintains a huge ecosystem of high-quality libraries. The strong community, and open-source licensing of Rust, ensure that Rust has resilience and is not subject to the whims of a single company or individual.

Companies large and small are adopting Rust. Amazon, Google, Huawei, Meta, Microsoft, Shopify, and many more are investing heavily in Rust. Rust is being used for backend apps, cloud infrastructure, distributed computing, networking, embedded development, data science, and many more (source: Rust community survey 2023).

AWS logo Bytedance logo Cloudflare logo Dropbox logo Google logo Huawei logo Meta logo Microsoft logo Mozilla logo NPM logo

If you want to learn more about Rust or adopting Rust in your team, org, or company, I can help! I can also help with Rust education and mentoring, team augmentation, or developing and maintaining Rust libraries and applications. Please get in touch for a chat about your needs and whether I can help.