AnyCompiler

Introduction to Rust

Rust is a systems programming language built around one central idea: memory safety without a garbage collector. Instead of tracking memory at runtime the way Python or JavaScript do, Rust's compiler checks your code's memory usage at compile time, using a set of rules called ownership.

Rust code compiles down to a native binary before it ever runs — the compiler (rustc) checks every type and every ownership rule up front. If your code violates any of them, nothing runs at all: you get a compile error instead of a crash, a memory leak, or a data race.

Why ownership matters

  • No garbage collector, no manual free() — ownership rules enforced at compile time mean memory is cleaned up automatically and deterministically, with none of the runtime overhead a garbage collector adds
  • No null pointer dereferences — Rust doesn't have null at all; a value that might be absent is represented with Option<T>, and the compiler forces you to handle both cases
  • No data races — the borrow checker guarantees that mutable data can never be accessed from two places at once, a problem most languages only catch at runtime, if ever
  • Performance on par with C and C++ — none of these guarantees cost anything at runtime; they're all checked once, at compile time

A quick preview

Here's a real Rust program, executed for real on this page's own compiler — not a mockup:

fn main() {
    let message: &str = "Hello from Rust!";
    println!("{}", message);
}
Output
Hello from Rust!

That's it — a variable with an explicit type, printed with println!. The next lesson runs your first full program and explains exactly what's happening.

Practice exercise

Declare a variable named version with type i32 set to 5, then print "Rust version:" followed by version using println!("Rust version: {}", version).