TL;DR

Learn Rust from scratch — discover why Rust is popular, set up your environment, and write your first program as a beginner

Key concepts

  • learn Rust
  • Rust for beginners
  • Rust programming language
  • Rust getting started
  • why learn Rust

Introduction to Rust

TL;DR: Rust is a systems programming language that guarantees memory safety without a garbage collector. In this lesson you'll write your first Rust program, learn why ownership makes Rust different, and see zero-cost abstractions in action. Estimated: 15 minutes. → Jump to code examples

Welcome to your first lesson in Rust programming! In this introduction, we'll cover what Rust is, why it's unique, and what makes it an excellent choice for modern software development.

What is Rust?

Rust is a systems programming language that focuses on safety, concurrency, and performance. It was originally developed by Mozilla Research and has since become one of the most loved programming languages according to Stack Overflow's annual developer survey.

Your First Rust Program

Every programming journey starts with "Hello, World!" — hit Run to see Rust in action:

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

That's it! Every Rust program starts with a fn main() function — it's the entry point. The println! macro (the ! means it's a macro, not a regular function) prints text to the screen.

Try it! Change the message inside the quotes and run it again.

Key Features

Memory Safety Without Garbage Collection

fn main() {
    // Variables are immutable by default
    let name = "Rust";

    // Use mut to make a variable mutable
    let mut count = 0;
    count += 1;

    println!("Learning {} - Count: {}", name, count);
}

Try it! Change name to your own name, or increment count a few more times.

Zero-Cost Abstractions

Rust provides high-level features that compile down to efficient low-level code:

fn main() {
    // Tuples group different types together
    let point = (10, 20);
    println!("x = {}, y = {}", point.0, point.1);

    // Arrays have a fixed size, known at compile time
    let numbers = [1, 2, 3, 4, 5];
    println!("First number: {}", numbers[0]);
    println!("Array length: {}", numbers.len());
}

Try it! Change the values in the tuple or add more numbers to the array.

Why Learn Rust?

  1. Safety: Rust's ownership system prevents common bugs at compile-time
  2. Performance: Zero-cost abstractions and no garbage collector
  3. Modern Tooling: Excellent package manager (Cargo) and documentation
  4. Growing Ecosystem: Active community and increasing adoption

Getting Started

To start coding in Rust, you'll need to:

  1. Install Rust using rustup
  2. Set up your development environment
  3. Learn the basic syntax — covered in Variables and Control Flow
  4. Understand Rust's ownership model

We'll cover each of these topics in detail in the upcoming lessons.

Functions in Rust

Rust lets you define your own functions to organize code. Functions can take parameters and return values:

fn greet(name: &str) -> String {
    format!("Hello, {}! Welcome to Rust.", name)
}

fn add(a: i32, b: i32) -> i32 {
    a + b // No semicolon = this is the return value
}

fn main() {
    let message = greet("learner");
    println!("{}", message);

    let result = add(5, 7);
    println!("5 + 7 = {}", result);
}

Notice that Rust functions return the last expression without needing a return keyword (as long as you leave off the semicolon). We'll cover functions in detail in a later lesson.

Try it! Change the name passed to greet, or write a multiply function that returns a * b.

Interactive Playground

Practice what you've learned! Edit and run the code below to experiment with Rust.

fn main() {
    // Try changing these values!
    let language = "Rust";
    let year = 2024;

    // String formatting in Rust
    println!("Learning {} in {}!", language, year);

    // Basic arithmetic
    let a = 10;
    let b = 20;
    println!("{} + {} = {}", a, b, a + b);

    // Arrays
    let numbers = [1, 2, 3, 4, 5];
    println!("First number: {}", numbers[0]);
    println!("Array length: {}", numbers.len());
}

Try these exercises:

  1. Change the language variable to your favorite programming language
  2. Add more numbers to the vector
  3. Instead of doubling, try multiplying the numbers by 3
  4. Add a new variable and include it in the first println statement

Pro Tip: The best way to learn Rust is by practicing. Try modifying the code examples above and experiment with them in the Rust Playground.

Key Takeaways

  • Rust is a systems programming language focused on safety, concurrency, and performance
  • It guarantees memory safety without a garbage collector through its ownership system
  • Variables are immutable by default — you opt into mutability with mut
  • Rust catches many common bugs at compile time, before your code ever runs
  • The language has excellent tooling: Cargo (package manager), rustfmt (formatter), and clippy (linter)

Next Steps

You've seen what makes Rust different: compile-time safety, immutability by default, and zero-cost abstractions. But we've only scratched the surface of how Rust thinks about data. In the next lesson, we'll explore variables and data types in depth — how Rust's type system decides what a value is, what numeric, boolean, and character types are available, and how to convert between them safely. Understanding the type system is essential because it's the foundation that makes all of Rust's safety guarantees possible.

Continue to Variables and Data Types -->