Beginner Fundamentals

Introduction

Rust is a systems programming language focused on speed, reliability, and memory safety. It lets you write low-level code with the kind of safety guarantees usually found only in higher-level languages.

Why Rust

  • Memory safety without a garbage collector, checked at compile time.
  • Performance comparable to C and C++.
  • A strong type system that catches many bugs before the program runs.
  • Great tooling: a compiler, package manager, and formatter built in.

Memory safety without a GC

Many languages use a garbage collector to free unused memory at runtime, which costs performance. Rust instead uses an ownership system verified by the compiler. There is no GC pause, yet you avoid common bugs like use-after-free and data races.

Your first program

Every Rust program starts at the main function. The println! macro prints text to the screen.

fn main() {
    println!("Hello, world!");
}

The ! after println means it is a macro, not a regular function. We will explore macros and functions in later lessons.