Loading
All articles
Python 14 min read

What Is the Rust Programming Language? A Simple Guide to the Fast Language That Won't Let You Crash

A friendly, jargon-free guide to Rust, the programming language that is as fast as C but stops whole families of memory bugs before a program ever runs. Learn about ownership, why tech giants are adopting it, and where it is used.

nbkhope
On this page

For decades, programmers building the most important software, like web browsers and operating systems, faced a hard choice. They could use languages like C and C++, which are blazing fast but let tiny mistakes with memory turn into crashes and security holes. Or they could use safer languages, which protect memory but are usually slower or need a helper running in the background.

Rust is a programming language that refuses to choose. It aims to be as fast as C while catching memory mistakes before the program ever runs. Microsoft, Google, Amazon and the Linux project have all started using it in some of their most sensitive code. This article explains, in plain language, what Rust is, how it pulls off that trick, and why so many people are excited about it.

Born from a broken elevator

In 2006, a programmer at Mozilla (the organization behind the Firefox browser) named Graydon Hoare came home to find that the elevator in his apartment building was broken, again. Its software had crashed. He's said that the frustration of climbing 21 flights of stairs got him thinking: why is so much software so fragile?

That night he started a personal project to design a language where those kinds of crashes would be much harder to cause. He named it Rust, after a family of tough, resilient fungi. Mozilla began sponsoring the project in 2009, hoping to use it to build a faster, safer browser, and Rust 1.0 was released in 2015.

The problem Rust solves: memory mistakes

Every program uses the computer's memory to hold its data: names, numbers, pictures, web pages. Picture memory as a giant wall of numbered lockers. A program asks for some lockers, uses them, and should give them back when it's done.

In C and C++, the programmer manages those lockers by hand, and it's easy to slip up: writing past the end of your lockers into someone else's, using a locker after giving it back, or giving the same locker back twice. These are memory-safety bugs, and they're not just crashes. Attackers can use them to break into computers.

Here's the same kind of mistake in C and in Rust:

The same mistake in C and in Rust. In C, an 11-letter name, Christopher, is copied into a box with room for 8 letters, inside a bank account record that also holds a balance of 100. The program runs and prints "Name: Christopher" and "Balance: 7497064": it silently corrupts the balance. In Rust, a program asks for item 5 of a list with only 3 items. The program stops with the message "index out of bounds: the len is 3 but the index is 5": it stops safely with a clear message. Real output from both programs. In C, the extra letters spilled into the next piece of memory and changed the balance from 100 to 7,497,064 without any warning. Rust checks the position and stops the program instead of touching the wrong memory

In the C program, the name "Christopher" didn't fit in its 8-letter box, so the extra letters spilled into the next locker, where the account balance was stored. The balance silently changed from 100 to 7,497,064, with no error at all. In Rust, a similar mistake stops the program immediately with a clear message, instead of quietly damaging other data.

How big is this problem? Bigger than you might think:

Memory mistakes are behind most serious security bugs. Share of security vulnerabilities caused by memory-safety problems, as published by each company. Microsoft products, 2019: about 70%. Google Chrome, 2020: about 70%. Android, 2019: 76%. Android, 2024: 24%. Sources: Microsoft Security Response Center, the Chromium project and the Google Security Blog. Android's share fell as Google wrote new code in memory-safe languages, including Rust

Microsoft and Google's Chrome team have each reported that about 70% of their serious security bugs come from memory-safety problems. On Android, Google started writing new code in memory-safe languages, including Rust, and reported that the share of memory-safety vulnerabilities fell from 76% in 2019 to 24% in 2024.

How other languages solve it, and how Rust does

Languages like Java, Go, Python and JavaScript avoid most of these bugs with a garbage collector: a helper that runs alongside your program, like a janitor, finding lockers nobody uses anymore and cleaning them out. That works well, but the janitor costs some speed and memory, and occasionally makes the program pause for a moment.

Rust takes a third path:

Rust's promise: safe and fast, without a garbage collector. C and C++: not safe from memory mistakes, no garbage collector, not easy to learn. Java, Go and Python: safe from memory mistakes, but they need a garbage collector, and they're easy to learn. Rust: safe from memory mistakes and no garbage collector, but not easy to learn. Rust gets safety and speed together by checking how memory is used before the program ever runs. The price: it takes longer to learn

Instead of a janitor that cleans up while the program runs, Rust has a very strict compiler, the tool that translates your code into a program, that checks how every piece of memory is used before the program is built. If the rules could be broken, it refuses to build the program. No janitor needed, and no memory-safety bugs in normal Rust code.

Ownership: Rust's big idea

Rust's rules are called ownership, and they work a lot like borrowing books from a library:

Rust's ownership rules, explained with a library book. Rule 1, one owner: every value has exactly one owner, like a book checked out to one person. Rule 2, lend it safely: lend it to many readers at once, or to one person who may write in it, never both. Rule 3, automatic cleanup: when the owner is done, the book goes back on the shelf automatically. The compiler checks these rules for every value in the program. If code could break them, it doesn't build, so whole families of memory bugs can't happen
  1. Every value has exactly one owner. If you give your book to a friend, it's theirs now. You can't keep reading it.
  2. You can lend it. Either to many people who only read it, or to exactly one person who may write in it, but never both at the same time. That way nobody reads a page while someone else is rewriting it.
  3. When the owner is done, it's cleaned up automatically. The book goes back on the shelf the moment its owner leaves, so memory is never forgotten or returned twice.

Here's what happens when you break rule 1:

let book = String::from("Rust for Beginners");
let friend = book;   // the book is given away
println!("{book}");  // ...but we still try to read it

The compiler refuses, with a message that reads like a helpful teacher:

The Rust compiler says no, a real message from Rust 1.78. The code creates a book, gives it to a friend, and then still tries to print the book. The compiler answered: error E0382, borrow of moved value: book. On line 3, value moved here. On line 5, value borrowed here after move. Then help: consider cloning the value, with the suggestion let friend = book.clone(). The program never runs. The compiler points at the exact line, explains the problem in words, and even suggests a fix: make a copy with .clone()

The program never runs. The compiler points at the exact line, explains that the book was "moved" (given away), and even suggests a fix: make a copy with .clone(). Rust's error messages are famous for being this friendly.

Lending looks like this. The & means "let this function borrow the book, but I still own it":

1fn count_letters(text: &String) -> usize {
2    text.len()
3}
4
5fn main() {
6    let book = String::from("Rust for Beginners");
7    let letters = count_letters(&book);
8    println!("\"{book}\" has {letters} characters");
9}

It prints "Rust for Beginners" has 18 characters. The book was lent out, returned, and is still ours to use.

What else Rust looks like

Here's the classic first program:

fn main() {
    println!("Hello, world!");
}

fn starts a function, main is where the program begins, and println! prints a line. And here's a small car, described with a struct (a bundle of named values) and an impl block that gives it abilities:

1struct Car {
2    color: String,
3    speed: u32,
4}
5
6impl Car {
7    fn accelerate(&mut self) {
8        self.speed += 10;
9    }
10}
11
12fn main() {
13    let mut my_car = Car {
14        color: String::from("red"),
15        speed: 0,
16    };
17    my_car.accelerate();
18    my_car.accelerate();
19    println!("My {} car is going {} km/h", my_car.color, my_car.speed);
20}

This prints My red car is going 20 km/h. Notice mut: in Rust, values can't be changed unless you say so. That's another small safety habit built into the language.

Is Rust fast?

Very. Rust compiles straight to machine code, like C, and has no garbage collector running in the background. We timed the same simple job, counting the prime numbers below 2 million, in six languages:

Speed test: Rust is as fast as C. Counting the prime numbers below 2 million, timed from start to finish, measured for this article as the median of 5 runs on one Windows laptop. Rust: 0.29 seconds. Go: 0.33 seconds. C: 0.35 seconds. JavaScript: 0.36 seconds. Java: 0.41 seconds. Python: 15.89 seconds, off the chart. Versions: Rust 1.78, Go 1.22, GCC 14, Node.js 26, Java 17 and Python 3.11. On a test this small, the top four are practically tied: in an earlier, noisier round, C and Rust both took 0.47 seconds

Rust came out on top at 0.29 seconds, but honestly, on a test this small, Rust, Go, C and JavaScript are practically tied: in an earlier round, while the laptop was busier, C and Rust took exactly the same time. The real point is that Rust plays in the same league as C, while also being memory-safe. Plain Python, for comparison, took almost 16 seconds.

Where Rust really shines is in big, long-running programs. Because there's no garbage collector, there are no surprise pauses. The chat app Discord famously rewrote one of its busiest services from Go to Rust in 2020 to get rid of the small, regular slowdowns caused by Go's garbage collector.

Where Rust is used

Where Rust is used. Firefox: Mozilla's browser, where Rust was born. Operating systems: parts of Linux, Windows and Android. The cloud: Amazon Web Services and Cloudflare servers. Discord: fast back-end services for millions of chats. Developer tools: the search inside VS Code, and Python's uv. Dropbox: the engine that syncs your files. Rust is chosen where speed and safety both matter: browsers, operating systems, cloud servers and tools millions of people rely on
  • Firefox: in 2017, Firefox shipped a new styling engine written in Rust, putting Rust code on hundreds of millions of computers.
  • Operating systems: Linux, the system behind most servers and every Android phone, started accepting Rust code into its core, the "kernel", in 2022, alongside C. Microsoft has rewritten parts of Windows in Rust, and Google uses it heavily in Android.
  • The cloud: Amazon built Firecracker, the technology behind its AWS Lambda service, in Rust. Cloudflare handles a huge share of the web's traffic with Rust-based software.
  • Apps and services: Discord, Dropbox (whose file-syncing engine is written in Rust) and Figma all use it.
  • Developer tools: when you search across files in Visual Studio Code, a Rust program called ripgrep does the work. Popular Python tools like uv and Ruff are written in Rust because they're dramatically faster.

In 2024, even the White House's Office of the National Cyber Director published a report urging software makers to move to memory-safe languages, a group that includes Rust.

The downsides

  • A steep learning curve. Ownership and borrowing are new ideas for most programmers. Beginners often spend their first weeks "fighting the borrow checker", the part of the compiler that enforces the lending rules, until it clicks.
  • Slow to compile. All those checks take time. Big Rust projects can take minutes to build, much longer than Go.
  • Not the easiest first language. For learning to program, Python or JavaScript are gentler starts. Rust rewards people who already know some programming.
  • Younger ecosystem. Rust has fewer ready-made libraries than C++, Java or Python for some areas, like games, AI research or apps with windows and buttons.
  • Safety isn't magic. Rust prevents memory-safety bugs, but it can't stop logic mistakes, like a calculator adding when it should subtract. And code inside unsafe blocks still relies on the programmer being careful.

A short history

A short history of Rust, as a timeline. 2006: Graydon Hoare starts Rust as a personal project. 2009: Mozilla begins sponsoring it. 2015: Rust 1.0 is released. 2016: first year as the "most loved" language. 2017: Firefox ships Rust code to millions. 2021: the Rust Foundation is created. 2022: Linux accepts Rust code. 2024: the White House urges memory-safe languages

Programmers clearly enjoy it: in Stack Overflow's huge yearly developer survey, Rust was voted the most loved (later renamed "most admired") language for nine years in a row, from 2016 to 2024. In 2021, Amazon, Google, Huawei, Microsoft and Mozilla founded the Rust Foundation, a nonprofit that now looks after the language.

Should you learn Rust?

  • Great reasons: you want to write software where speed and reliability really matter: system tools, game engines, browsers, embedded devices, cloud infrastructure or high-performance libraries. Even if you never use it at work, learning Rust teaches you how memory really works, which makes you a better programmer in any language.
  • Good to know: Rust is free and runs on Windows, Mac and Linux. The official website, rust-lang.org, offers a free online book, The Rust Programming Language (nicknamed "the book"), and an online playground where you can try Rust in your browser.

If you're curious about the languages Rust is often compared to, see What Is the C Programming Language?, What Is the C++ Programming Language? and What Is the Go Programming Language?

A small glossary

  • Rust: a programming language focused on speed and memory safety, released in 2015.
  • Memory: where a running program keeps its data.
  • Memory-safety bug: a mistake like using memory you don't own or after you gave it back. A leading cause of crashes and security holes.
  • Garbage collector: a helper that automatically cleans up unused memory while a program runs.
  • Compiler: the tool that translates code into a program, and in Rust's case, checks the ownership rules.
  • Ownership: Rust's rule that every value has exactly one owner, and is cleaned up when the owner is done.
  • Borrowing: temporarily lending a value to another part of the program, written with &.
  • Borrow checker: the part of the Rust compiler that enforces the lending rules.
  • Panic: Rust stopping a program on purpose when something is wrong, instead of continuing with bad data.
  • unsafe: a keyword that marks code where the programmer, not the compiler, guarantees safety.
  • Cargo and crates: Rust's build tool and its ready-made packages.

Wrapping up

Rust started with a broken elevator and a simple question: why does so much software crash? Its answer is ownership, a set of library-style rules that the compiler checks before your program is ever built. The result is a language as fast as C that stops whole families of memory bugs, the kind behind most serious security holes.

It asks more of you up front, and its compiler can feel strict. But that strictness is the point: every mistake it catches on your computer is one that never reaches anyone else's. That's why browsers, operating systems and cloud servers are slowly being rebuilt with a little help from a friendly orange crab.

Thanks for reading!

Know someone who would enjoy this? Send it their way.

More articles

Read next

Comments

Be kind and specific. Comments with links from new accounts appear after a moderator reviews them.