Skip to content

Beginner · Getting started with Rust · topic 1 of 50 · 20 min

What Rust is and why learn it

Explanation

Rust is a compiled programming language that is as fast as C and C++ but stops most memory bugs before the program ever runs. It has no garbage collector; instead, the compiler checks who owns each piece of memory. It is harder to learn than Python, but the programs it produces are fast, safe and reliable.

Two old problems: speed and safety

For decades, programmers had to choose. Languages like C and C++ give full control of memory and run very fast, but one small mistake can crash the program or open a security hole. Languages like Python, Java and JavaScript are safer, because a helper called a garbage collector cleans up memory for you, but that helper costs speed and memory, and it can pause the program at awkward moments.

Rust was designed to remove this choice. It was started at Mozilla, reached version 1.0 in 2015, and is now run by the Rust Foundation and an open community. Its promise is simple: the speed of C, with memory safety checked by the compiler.

A few words first

  • Compiler: a program that turns your source code into a machine-code file the computer runs directly. Rust's compiler is called rustc.
  • Compiled language: you compile once, then run the result many times. Python is interpreted: a program reads your code line by line every time it runs.
  • Memory safety: the program never reads memory it should not, never uses memory after freeing it, and never frees the same memory twice.
  • Garbage collector (GC): a helper that runs while your program runs and frees memory that is no longer used. Rust does not have one.

How Rust is safe without a garbage collector

Rust uses a set of rules called ownership. Every value has one owner, and when the owner goes away, the value is freed automatically. The compiler checks these rules before the program runs. If your code could use freed memory, it simply does not compile. You will spend modules 3 and 4 on ownership, because it is the heart of Rust.

Think of it like this: Think of a library book. In C, anyone can scribble in it, tear pages or return it twice, and nobody checks. In Python, a librarian follows you around and tidies up, which is safe but slow. In Rust, the rules are checked at the counter before you leave: one person holds the book, others may only read over their shoulder, and the book returns to the shelf the moment its holder is done.

Where Rust is used

Rust is used in places where both speed and safety matter. Well-known public examples include parts of the Linux kernel, parts of Android and Windows, the Firefox browser, AWS Firecracker (which runs serverless functions), Cloudflare's network services and Discord's backend services. It is also popular for command-line tools, WebAssembly in the browser, embedded devices and blockchains.

C / C++Python / JavaRust
SpeedVery fastSlower (Python) or medium (Java)Very fast
Memory safetyUp to youGarbage collectorChecked by the compiler
Learning curveHardGentleSteep at first
Typical useOS, games, driversApps, data, webSystems, tools, web services, Wasm

The honest trade-offs

  • The learning curve is steep. The first weeks feel like arguing with the compiler. This is normal and it passes.
  • Compiling takes longer than in Go or C, especially for big projects.
  • There are fewer Rust jobs than Java or Python jobs, especially for freshers in India.
  • For a quick data script or a simple website, Python or JavaScript is usually the better choice.

Common mistakes when starting

  • Fighting the compiler instead of reading it. Rust's error messages are some of the best of any language: they often show the exact fix. Read the whole message.
  • Skipping ownership. Everything else in Rust builds on it. Go slowly through modules 3 and 4.
  • Learning Rust as your very first language with no patience. It is possible, but expect to move slowly.
Tip: Rust's official book, "The Rust Programming Language", is free online and excellent. Read the matching chapter after each module of this course.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

What Rust is and why learn it · 1/7

Rust: fast and safe

Welcome to Rust. In this lesson you will learn what Rust is, and why so many companies now use it.

Prefer a video by a teacher? Find free videos on “what is rust programming language why learn rust explained” on YouTube ↗

In real life: A payments service that must never crash

A company running UPI payments processes thousands of requests every second. A crash or a memory bug can lose money and trust. A team might rewrite its most busy service in Rust: the service uses less memory than one built on a garbage-collected language, it has no garbage-collector pauses during peak hours like Diwali sales, and whole kinds of bugs (use-after-free, data races) are caught by the compiler before the code is deployed.

Practice (0/2 done)

Task 1 · Question

Which statement about Rust is true?

Task 2 · Practice

Write a short note (5 to 8 lines) for a friend: what Rust is, one reason a company would pick it, and one reason they might not.

Quick quiz

Question 1

1.What is a compiler?

Question 2

2.How does Rust free memory?

Question 3

3.Which is a fair downside of Rust?

Question 4

4.For which job is Rust usually NOT the first choice?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What is a compiler?

Answer: A program that turns source code into machine code before it runs

A compiler translates your code into a file the computer can run directly. Rust's is called rustc.

How does Rust free memory?

Answer: Through ownership: a value is freed when its owner goes out of scope

Ownership rules make freeing automatic and predictable, and the compiler checks them.

Which is a fair downside of Rust?

Answer: It has a steep learning curve at the start

Rust is fast and runs on many systems, but beginners need time to learn ownership and borrowing.

For which job is Rust usually NOT the first choice?

Answer: A ten-line script to rename some files once

For a quick one-time script, Python or a shell is faster to write. Rust shines when speed and reliability matter.

How does Rust decide when to free heap memory?Related

Answer: Ownership rules let the compiler insert the free at the right point

Rust frees a value when its owner goes out of scope, decided at compile time.

From Memory 101: the stack and the heap

Why does Rust invalidate s1 after a move?Related

Answer: To prevent the heap data being freed twice

If both owned the data, both would drop it, causing a double free.

From The ownership rules and moves

Compared with Java or Python, the number of Rust-first jobs in India is…Related

Answer: Smaller, and often requires prior experience

Rust roles exist but are fewer and often not entry level.

From Where Rust is used and the job market

Which flag asks the compiler to optimise the program for speed?Related

Answer: -O2

-O2 (capital letter O) turns on optimisation. Lowercase -o names the output file.

From What C++ is and how compiling works

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 3 more topics in “Getting started with Rust” before its exam: Installing Rust with rustup, Your first program and cargo, Variables, mutability, shadowing and constants.
  2. Module 1 exam: Getting started with Rust · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
  3. Then the next module, Types, control flow and functions. 50 topics left in the course before the final exam.