Beginner · Getting started with Rust · topic 1 of 50 · 20 min
What Rust is and why learn it
Explanation
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.
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 / Java | Rust | |
|---|---|---|---|
| Speed | Very fast | Slower (Python) or medium (Java) | Very fast |
| Memory safety | Up to you | Garbage collector | Checked by the compiler |
| Learning curve | Hard | Gentle | Steep at first |
| Typical use | OS, games, drivers | Apps, data, web | Systems, 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.
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
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)
Which statement about Rust is true?
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
Read more (free)
Related help
Related topics
- Installing Rust with rustupGetting started with Rust · same module
- Your first program and cargoGetting started with Rust · same module
- Variables, mutability, shadowing and constantsGetting started with Rust · same module
- Memory 101: the stack and the heapOwnership: Rust's big idea
- The ownership rules and movesOwnership: Rust's big idea
- Where Rust is used and the job marketRust careers and interviews
Questions people ask about this
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.
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.
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.
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.
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
- 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.
- Module 1 exam: Getting started with Rust · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
- Then the next module, Types, control flow and functions. 50 topics left in the course before the final exam.