Rust Questline: Why Rust Exists and What It Promises
The first lesson of the Novice level explains why Rust exists, how ownership delivers memory safety without a garbage collector, and where the language stands beside C, C++, Go and Python.
The present article opens Rust Questline, a course of 55 lessons that leads a reader who already programs in another language, with Python as the reference point, from a first program to unsafe code, macros and performance. This first lesson of the Novice level addresses the reason for which Rust exists and what the language promises, so that every later rule, from ownership to lifetimes, can be read as a consequence of one design decision. At the end of the lesson the reader will be able to explain the problem that Rust solves, which is memory safety without a garbage collector, and to situate Rust next to C, C++, Go and Python. All the code was compiled and run with Rust 1.100.1 and the 2024 edition. The secret weapon of the language is that the compiler, and not a runtime, proves the memory discipline of a program before the program executes.
The Problem: Programs That Manage Their Own Memory
Languages such as C and C++ give the programmer direct control of memory, which explains both their speed and the family of defects that accompanies them. Four classes are usually listed: use after free, double free, access outside the bounds of a buffer and data races between threads. In these languages each of them produces undefined behaviour, that is, a program for which the language standard promises nothing, so the failure may be a crash, a corrupted value or a security vulnerability.
The consequences are measurable. According to the security team of Google, the share of memory-safety vulnerabilities in Android fell below 20% of the total in 2025 for the first time, a decline that the team attributes to writing new code in memory-safe languages, Rust among them (Google Security Blog). A well-known space station of science fiction was destroyed because one exhaust port had been left unprotected, although the rest of the structure was formidable. A program in C or C++ resembles that station in one respect: a single unchecked access among millions of lines is enough to compromise the whole process, which means that memory safety is a property of the entire program and not only of its best-written parts. The analogy, however, stops at this point, because the defects of a real code base are not one hidden port but a large number of ordinary mistakes that review and testing find only in part.
Two traditional answers exist. The first is the garbage collector, used by Go, Java and Python, which keeps programs safe by finding unused memory while the program runs and which therefore adds work and memory overhead at run time. The second is manual discipline, as in C, which adds no overhead but leaves every defect to the programmer. Rust adopts a third answer, described by the official book as a set of ownership rules that the compiler checks, so that a program that violates them does not compile and a program that obeys them pays no run-time cost for them (The Rust Programming Language, chapter 4).
Ownership: Memory Safety Without a Garbage Collector
Three rules constitute the core of the model: each value has exactly one owner, there can be only one owner at a time, and the value is dropped when its owner goes out of scope. The following program makes the third rule visible by giving a type a Drop implementation, which is a function that runs at the moment a value is released. The trait itself is examined in a later lesson, and here it serves only to print a message.
struct Resource {
name: &'static str,
}
impl Drop for Resource {
fn drop(&mut self) {
println!("released {}", self.name);
}
}
fn main() {
let _outer = Resource { name: "outer" };
{
let _inner = Resource { name: "inner" };
println!("inner scope ends");
}
println!("main ends");
}
// Output:
// inner scope ends
// released inner
// main ends
// released outer
The release of inner happens at the closing brace of its block and the release of outer at the end of main, in the reverse order of creation. Nothing in the program frees memory explicitly, and no collector decides when to do it; the compiler inserts each release at the point where the owner ceases to exist. This is a determinism that a tracing collector does not offer, because the instant of a collection is not part of the program text.
Ownership can also move. Passing a value to a function transfers the ownership to the function, and the value is then released when that function ends, which is shown by the following example.
struct Resource {
name: &'static str,
}
impl Drop for Resource {
fn drop(&mut self) {
println!("released {}", self.name);
}
}
fn consume(resource: Resource) {
println!("consuming {}", resource.name);
}
fn main() {
let shield = Resource { name: "shield" };
consume(shield);
println!("after the call");
}
// Output:
// consuming shield
// released shield
// after the call
The release of shield precedes the last message because the function consume owns the value when it ends. Since the variable shield no longer owns anything after the call, the compiler rejects any later use of it, a rule whose consequences are developed in the lessons of the Apprentice level.
Compile-Time Guarantees
Memory defects are prevented by different mechanisms, and the following table identifies five of them together with the moment at which each one acts. Three of them are examined in this lesson through code that the compiler refuses.
| Defect | Mechanism in safe Rust | Moment |
|---|---|---|
| Use after free and double free | Single owner and release at the end of the scope | Compile time |
| Dangling reference | The borrow checker compares the lifetime of a reference with that of its value | Compile time |
| Data race | Rules of borrowing, together with the traits Send and Sync |
Compile time |
| Null pointer | There is no null reference; absence is the type Option<T> |
Compile time |
| Access outside a buffer | Every index is checked | Run time |
The last row differs from the others, because bounds checking cannot be decided before the program runs, since an index may depend on the input. Rust therefore does not prevent the error but converts it from undefined behaviour into a controlled failure, called a panic, which stops the program with a message. The following program indexes a vector with a position that exceeds its length.
fn main() {
let scores = vec![10, 20, 30];
let position = scores.len() + 2;
println!("{}", scores[position]);
}
Running it prints the following diagnosis and ends the program, without reading any memory beyond the vector.
thread 'main' panicked at src/main.rs:4:26:
index out of bounds: the len is 3 but the index is 5
These guarantees apply to safe Rust, which is the language without the unsafe keyword. The keyword exists because some operations, such as calling a foreign function, cannot be verified by the compiler, and it marks the places in which the programmer assumes the proof. The Android team reports that about 4% of its Rust code lies inside unsafe blocks, and the last level of this course is devoted to writing them correctly.
Zero-Cost Abstractions
An abstraction is called zero-cost when code that does not use it pays nothing for it, and when code that uses it could not be written by hand with a lower cost. The formulation comes from the C++ community and Rust adopts it as a design goal. The following program computes the sum of squares of the first ten integers in two ways, with an explicit loop and with an iterator chain, which is a higher-level description of the same computation.
fn sum_of_squares_loop(values: &[u64]) -> u64 {
let mut total = 0;
for value in values {
total += value * value;
}
total
}
fn sum_of_squares_iterator(values: &[u64]) -> u64 {
values.iter().map(|value| value * value).sum()
}
fn main() {
let values: Vec<u64> = (1..=10).collect();
println!("{}", sum_of_squares_loop(&values));
println!("{}", sum_of_squares_iterator(&values));
assert_eq!(sum_of_squares_loop(&values), sum_of_squares_iterator(&values));
}
// Output:
// 385
// 385
Both functions return the same value, and the official book, in its comparison of loops and iterators, reports that the iterator version compiles to code that performs as well as the loop (chapter 13.4). The lesson on iterators examines why. The absence of a garbage collector belongs to the same principle: a Rust program contains no collector thread, no pause for a collection and no reference counter unless the programmer asks for one explicitly. The price is paid elsewhere, in longer compilation and in a learning curve that the Apprentice level is designed to flatten.
The Contrast with Python: Counting at Run Time
CPython manages memory by counting references. Every object stores the number of names that point to it, the interpreter updates that number on each assignment, and the object is released when the number reaches zero. A cyclic collector complements the counter, because two objects that point to each other never reach zero by themselves. This mechanism was described in detail in the article on reference counting and garbage collection. The following script, run with Python 3.12, shows both behaviours; the automatic collector is disabled at the start so that the output is deterministic.
import gc
import sys
class Node:
def __init__(self, name):
self.name = name
self.other = None
def __del__(self):
print(f"released {self.name}")
gc.disable() # Only the reference counter acts, so the demonstration is deterministic.
first = Node("first")
print(sys.getrefcount(first)) # Output: 2 (the variable and the call argument)
alias = first
print(sys.getrefcount(first)) # Output: 3
del alias
del first # Output: released first
left, right = Node("left"), Node("right")
left.other, right.other = right, left
del left, right
print("cycle unreachable but not released")
print(gc.collect() > 0) # Output: released left, released right, then True
The object first is released at the instant in which its last name disappears, which resembles the behaviour of the Rust program above. The difference lies in who decides. In Python the interpreter maintains a counter that changes while the program runs, and the pair left and right survives until a collection explicitly examines it. In Rust the point of release was fixed at compile time from the structure of the program, no counter exists, and a cycle of owned values cannot be built by accident in safe code. When a program genuinely needs shared ownership, Rust offers counting as an explicit library type, Rc, whose lesson belongs to the Expert level; the counter is then a choice and not a tax.
Rust Beside C, C++, Go and Python
Placing the five languages in a single table clarifies where the design of Rust sits. The comparison concerns memory management only, and it ignores other aspects, such as ecosystem or learning cost, that influence a real decision.
| Language | Memory management | Memory-safe by default | Run-time cost of management |
|---|---|---|---|
| C | Manual allocation and release | No | None added, with every defect left to the programmer |
| C++ | Manual, with destructors and smart pointers by convention | No, since the compiler does not enforce the conventions | None added |
| Go | Concurrent mark-sweep garbage collector | Yes in ordinary code; data races are found by a tool and not prevented by the compiler | Collector work and memory overhead |
| Python | Reference counting and a cyclic collector | Yes | Counter updates and collections |
| Rust | Ownership checked by the compiler | Yes in safe code | No collector and no counter by default |
The Go collector is described in the official guide as a mark-sweep design. Rust is thus the only language of the table that combines compile-time proof with the absence of a collector, a combination whose cost is that the compiler rejects some programs that would be correct in the other languages.
Editions: Evolving Without Breaking
The language changes through editions, which are opt-in sets of changes that could otherwise break existing code. Four editions exist, those of 2015, 2018, 2021 and 2024, and the 2024 edition was stabilized in Rust 1.85, released on 20 February 2025, which the release team describes as the largest edition so far (announcement). A crate selects its edition in Cargo.toml, as follows.
[package]
name = "questline"
version = "0.1.0"
edition = "2024"
Crates compiled with different editions interoperate, which prevents the ecosystem from splitting, and cargo fix automates most of the migration from one edition to the next, as the Edition Guide states. Rust itself is released every six weeks; the current stable release is 1.100, published on 12 November 2026, and it announces no new edition. This course therefore requires Rust 1.85 or later and uses the 2024 edition throughout.
Where Rust Is Used
Three pieces of evidence indicate the extent of adoption. The Android team reports an estimated reduction of more than a thousand times in memory-safety vulnerability density for Rust code against C and C++, a figure that the team itself calls conservative and that derives from about five million lines of Rust with a single potential vulnerability found. In December 2025 the maintainers of the Linux kernel agreed that Rust would cease to carry the label of experiment, as LWN reported. Finally, the Stack Overflow Developer Survey of 2025 ranks Rust as the most admired language, with 72% of the respondents who use it wishing to continue (survey). Admiration is not the same as widespread use, so the figure measures satisfaction and not market share.
It Is a Trap: Mistakes Carried Over from Other Languages
Three habits from other languages produce compile errors in the first week, and each one shows a guarantee in action. The first is assuming that an assignment shares a value, as it does in Python, where moved = original creates a second name for the same object. In Rust the assignment of a String transfers the ownership, and the old name becomes unusable.
fn main() {
let original = String::from("Questline");
let moved = original;
println!("{original} {moved}");
}
The compiler reports the move and points to the line at which it happened.
error[E0382]: borrow of moved value: `original`
--> src/main.rs:4:16
|
2 | let original = String::from("Questline");
| -------- move occurs because `original` has type `String`, which does not implement the `Copy` trait
3 | let moved = original;
| -------- value moved here
4 | println!("{original} {moved}");
| ^^^^^^^^ value borrowed here after move
The second habit is assuming that a reference keeps its value alive, as every name does in a language with a collector. In Rust a reference cannot outlive the value that it points to, and the following program tries to use a reference after its value left the scope.
fn main() {
let reference;
{
let value = 42;
reference = &value;
}
println!("{reference}");
}
The diagnostic names the three relevant points: the declaration of the value, the end of its scope and the later use of the reference.
error[E0597]: `value` does not live long enough
--> src/main.rs:5:21
|
4 | let value = 42;
| ----- binding `value` declared here
5 | reference = &value;
| ^^^^^^ borrowed value does not live long enough
6 | }
| - `value` dropped here while still borrowed
7 | println!("{reference}");
| --------- borrow later used here
The third habit is assuming that a thread may use any local variable, since in Python threads share the whole interpreter state. A thread that borrows a variable of the function that created it may run after the function has ended, and the compiler refuses the program.
use std::thread;
fn main() {
let mut counter = 0;
let handle = thread::spawn(|| {
counter += 1;
});
counter += 1;
handle.join().unwrap();
}
The first error of the output, trimmed here to its relevant lines, states the problem and suggests the keyword that transfers ownership to the thread.
error[E0373]: closure may outlive the current function, but it borrows `counter`, which is owned by the current function
--> src/main.rs:5:32
|
5 | let handle = thread::spawn(|| {
| ^^ may outlive borrowed value `counter`
6 | counter += 1;
| ------- `counter` is borrowed here
|
help: to force the closure to take ownership of `counter` (and any other referenced variables), use the `move` keyword
|
5 | let handle = thread::spawn(move || {
| ++++
In each case the program that would have failed at run time, or silently corrupted data, fails at compile time with a message that locates the cause. This is the practical meaning of the promise: the first compilations are demanding, and the errors that remain after them are of a different kind.
When to Choose Rust and When Not
The decision depends on what a program must guarantee and on what it can afford to spend. The following table summarizes the situations that favour each option, within the limits of the comparison of this lesson.
| Situation | Reasonable choice | Reason |
|---|---|---|
| Scripts, prototypes and data exploration | Python | The speed of writing matters more than the speed of execution |
| Network services in which a collector pause is acceptable | Go or Rust | Both are adequate, and the team experience decides |
| Components that must be fast, predictable and safe: kernels, browsers, embedded systems, parsers of untrusted input | Rust | No collector and no undefined behaviour in safe code |
| Performance-critical extensions of a Python program | Rust | A later side-quest examines how a Rust library is called from Python |
| Large existing C or C++ code bases | Keep them and write new components in Rust | A rewrite is rarely justified by safety alone |
Conclusion
It is concluded that Rust exists to remove a class of defects that systems languages leave to the programmer, and that it does so by moving the proof from the run time, where Python and Go place it, to the compile time. Ownership supplies the model, the absence of a collector supplies the performance, zero-cost abstractions allow the high-level style of the examples, and editions allow the language to evolve without breaking existing programs. The objectives of the lesson are thereby met: the problem that Rust solves has been stated, and the language has been placed next to C, C++, Go and Python. The next lesson, Rust Questline: Installing the Toolchain and Meeting Cargo, installs the compiler, creates the first project with Cargo and builds the program that every later lesson extends.