Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to Rust  ›  Lesson

What Rust Is and Why People Choose It

What is Rust? 12 minRust is a compiled systems language that gives C-like speed and control while its compiler rules out whole classes of memory bugs before the program runs.

What Rust Is and Why People Choose It

Imagine a program that tracks every book in a busy lending library. It must answer thousands of requests a second, and it must never mix up who has which book. Most languages make you choose: fast but risky (C, C++) or safe but slower (Python, Java). Rust was built to refuse that trade.

The rule

Rust: machine-code speed, with memory mistakes caught at compile time.

Rust is a compiled language. The compiler, rustc, turns your source into a native executable, the same kind of file a C compiler produces. There is no interpreter and no virtual machine at run time.

Rust has no garbage collector. Instead, every value has one owner, and the value is freed the moment its owner goes out of scope. The compiler works out exactly where that happens, so memory is released without a pause to scan for garbage.

The compiler is strict on purpose. Its borrow checker rejects programs that could read freed memory, keep a pointer to something that has moved, or let two threads change the same data at once. In C those are run-time crashes; in Rust they are compile errors.

fn main() {
    let title = String::from("The Salt Road");
    println!("Now lending: {title}");
}

That is a complete program. fn main is where it starts, let creates a variable, and println! (the ! marks a macro) prints a line.

Where Rust shows up: command-line tools, web servers, browsers, game engines, embedded devices, and code compiled to WebAssembly. Anywhere speed and reliability both matter.

The shortcut

When someone asks "why Rust here?", check three boxes: speed, safety, no runtime.

Should the library's search service be written in Rust?Step 1 of 4
  1. Speed

    It answers thousands of lookups a second. Compiled native code with no garbage-collector pauses fits well.

The trap is believing Rust is "safe, so nothing can go wrong". It prevents memory errors and data races, not logic errors. If you lend the same book to two people, the compiler will not notice.

Drills

Answer fast — trust the rule.

quick drill

How does Rust free memory that a program no longer needs?

quick drill

What does rustc produce from your source code?

quick drill

Which bug does the Rust compiler reject before the program runs?

quick drill

In println!("Now lending: {title}");, what does the ! tell you?

Remember

  • Rust compiles to native code, has no garbage collector, and frees each value when its owner goes out of scope.
  • Shortcut: speed, safety, no runtime. If a project needs all three, Rust fits.
  • Trap: Rust stops memory bugs and data races, not logic bugs.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainPitch Rust to a teammate

Your team maintains a slow Python service and a crash-prone C program. Explain what Rust would change for each one, and name one real cost of switching.