Loading…

Getting started with ... Rust

In this series, we look at the most loved languages according to the Stack Overflow developer survey, the spread and use cases for each of them and collect some essential links on how to get into them. First up: Rust.

Article hero image

In this series, we look at the most loved languages according to the Stack Overflow developer survey, the spread and use cases for each of them and collect some essential links on how to get into them. First up: Rust.

Intro

Despite its relatively tiny userbase—roughly 5% of programmers use it—Rust has consistently come in number one as the most loved language in our developer survey for the past few years, thanks to its small but devoted community.

Rust was first created by Graydon Hoare. What began as a side project later got picked up by Mozilla, who remain one of the sponsors today.

Since its first release in 2009, it has seen a steady ascent in popularity. Over 5000 people have contributed to the Rust codebase. Some enthusiasts wonder if it could replace C++. While it might not be a beginner's language, Rust is gaining ground in the software industry and can be a valuable tool in any developer’s skill set.

The rise of Rust

Just how popular is Rust? If you look at the spread of questions around Rust, you can see it has grown continuously through 2020, although it’s still far from common.

On the TIOBE index, Rust comes in at #25 in November 2020. Most notably, it has continually led the Most Loved ranking in the Stack Overflow survey since 2016.

Most loved languages in 2020 in the Developer Survey

With recent layoffs at Mozilla, some worry that this might threaten support for Rust. But the Rust Core Team addressed this in an update announcing the creation of an independent Rust foundation. In their statement, they point out that “many Mozilla employees in Rust leadership contributed to Rust in their personal time, not as a part of their job” and that they have “leaders and contributors from a diverse set of different backgrounds and employers.”

Many companies sponsor Rust with infrastructure resources, including ARM, Microsoft Azure, Integer32, 1Password, Google Cloud, Mozilla, Sentry, and Amazon Web Services.

AWS has affirmed their commitment by stating “at AWS, we love Rust, too, because it helps AWS write highly performant, safe infrastructure-level networking and other systems software.” And more recently they followed up with an outline of their plan to contribute with a dedicated Rust team.

Rust doesn’t look to fade away anytime soon, so learning it now won’t leave you with a useless skill and wasted time.

Who is using it?

Many companies are using Rust—according to the official Rust book, the use cases include “command line tools, web services, DevOps tooling, embedded devices, audio and video analysis and transcoding, cryptocurrencies, bioinformatics, search engines, Internet of Things applications, machine learning, and even major parts of the Firefox web browser.”

Amazon first used Rust for Firecracker, which launched in 2018. In the above-mentioned post in November 2020, Shane Miller, senior software engineering manager at AWS, said “Rust is a critical component of our long-term strategy.”

The team at Dropbox wrote about betting on Rust as one of the best decisions they made. “More than performance, its ergonomics and focus on correctness has helped us tame sync’s complexity. We can encode complex invariants about our system in the type system and have the compiler check them for us.”

Some people have spotted Apple hiring for Rust roles. And as people in the discussion on Hacker News point out, it is likely that most large companies experiment with it. Still noteworthy, Google’s new OS Fuchsia is built with Rust. Others using it include npm, Discord, and Figma.

It’s worth noting that only 5% of developers are currently using Rust. Even though it is loved, it’s not widely used, and low adoption could factor into consideration of its long-term prospects.

Who’s it for?

Developers looking for safety and speed

First and foremost, Rust is written for speed and stability. The process of writing code is usually slowed down when you run into issues. Steve Donovan describes this as safe by default. According to him, Rust principles work as guardrails. Read more on those five principles here.

For teams

Rust can also work for a team of programmers with varying systems programming knowledge by leveraging the strictness of the compiler. This way, less experienced programmers don’t need to rely on senior developers to catch their bugs and allowing more people to work together on the same codebase without having to worry about keeping track of all the moving parts, a huge help on larger code bases. Furthermore, `rustfmt` improves consistent coding style across a team.

Programmers of embedded systems

Embedded programmers praise the sophisticated type system, its easy cross-compiling, and Rust as a modern, zero-overhead language, offering a real alternative to C/C++ in the embedded space.

For students

While many say it is not a beginner language as such, the community makes an explicit commitment to answering student and beginner questions.

The goals and motivations for Rust’s creators include better compile-time error detection and prevention, clarity and precision of expression, run-time efficiency, high-level zero-cost abstractions, and safe concurrency. Rust has some great compiler error messages; users stress that they are not only friendly in tone and worth reading the entire message since it is full of great information.

Rust is suitable for anything from work with high-performance servers, command-line utilities, operating system modules, web browsers or embedded applications. A recent keynote discusses industrial, automotive, and avionics use cases.

Why you shouldn't learn it

Rust is not a beginner’s language, and as such, most learning materials build off of previous programming skills. Knowing at least one language helps, but some developers have Rust as their first introduction to a systems programming language. Most guides recommend prior C or C++ knowledge. Many Rust tutorials are about rewriting tools previously written in another language. While learning it as your first programming language might be a brave endeavor, it might not be for everyone.

If you are new to programming, Rust might not be for you. There are many other languages that are considered better beginner languages. For those already familiar with C++, it’s worth noting, it is considered syntactically similar to Rust. Also see: Why is Rust difficult?

What are some of the key concepts?

Well-defined semantics make Rust easy to understand.

  • Abstraction. In Rust, generics and traits allow reusing one piece of code. The compiler then generates multiple independently optimized pieces of native machine code. However, Rust has zero-cost abstraction as one of its core principles.
  • Functions. As in many languages, functions allow us to containerize sections of our code into reusable units. Rust allows functions to both pass-by-value and pass-by-address.
  • Mutability. Rust’s variables are immutable by default and the compiler guarantees that only one section of code can mutate a value at a time, which provides an additional layer of safety compared to other popular languages such as C++. While primarily aimed at improving memory safety in multi-threaded applications, this also provides valuable guarantees in complex single-threaded programs.

Rust allows some flexibility here, for those situations where mutating in place may be more efficient: it allows you to explicitly declare that a variable will be mutable. By requiring you to clearly state your intent, Rust nudges you to make the code’s purpose clearer - both for other programmers reading the code, and for the compiler itself.

  • Polymorphism. Many popular languages – including C++ and Java – use ‘inheritance’ to create code that can work with data of different types. Rust takes a rather different approach – instead of subclasses and inheritance, Rust uses generics to abstract types, and traits to guarantee that those types will be able to behave in certain ways.
  • Ownership. Rather than using garbage collection or needing the developer to allocate memory, Rust solves the problems by giving the compiler a set of rules to check. This also affects borrowing and slices.

Resources

Part of the Rust community’s reputation for being welcoming comes from the wealth of material provided for learners by the Rust community and the Rust Core Team.

Official Rust materials

  • The official Rust Programming Language book is the primary introduction to the language. It covers everything you could want to know about the language. If you love paper, it is available in print too. Note, if you are learning or teaching and English is not your strong point, it’s available in 20+ other languages.
  • If that’s not enough, rust-lang.org/learnprovides a thorough starting point. Here you can find everything from a comprehensive guide to the Rust standard library APIs, to a guide to the Rust editions, a book on Rust’s package manager and build system, or in-depth explanations of the errors you may see from the Rust compiler.
  • Look through the official Rust Youtube. This channel publishes videos from Rust conferences as well as talks and lectures from other places.
  • ctjhoa/rust-learning: has an extensive collection of blog posts, articles, videos, etc. for learning Rust, many by Rust team members.
  • The official Twitter account is also active and shares interesting projects and other useful resources.
  • Rust By Example is a collection of runnable examples that illustrate various Rust concepts and standard libraries.
  • Dave Herman, co-founder of Mozilla research, has his own short series of videos on Rust programming.

There are Rust lovers out there documenting their own journey into Rust in an effort to create bite-sized guides to the basics, as well as learning by example use cases:

Entry-level resources and tutorial series

For devs familiar with other languages

Tutorials geared towards programmers of specific other languages.

Advanced:

Other resources:

Learn from specific use cases, demos, talks.

Talk: On stage after the Stack Musical at !!Con

Communities:

Top conferences:

https://rustconf.com/

https://www.rustlatam.org

https://rustfest.global

http://www.rust-belt-rust.com

Rust on Stack Overflow. Data March 2021

Interesting Stack Overflow questions:

More about Rust, or in fact any other technology tag you can find on the Rust wiki page.

Interested in job opportunities with Rust? Check out those on our job board?

Learning or teaching Rust and got a recommendation for our list? Add yours in the comments section!

Add to the discussion

Login with your stackoverflow.com account to take part in the discussion.