Introduction to Rust

Introduction to Rust

Learn what Rust is, why it matters, and write your first Rust program.

10 min read4 learning objectives

What You'll Learn

  • Understand what Rust is and its key features
  • Learn about memory safety and ownership
  • Write and run your first Rust program
  • Understand basic Rust syntax

Introduction to Rust

Rust is a modern systems programming language that focuses on safety, speed, and concurrency. It was created by Mozilla Research and has quickly become one of the most loved programming languages by developers worldwide.

Key Features of Rust

Memory Safety

Rust's ownership system ensures memory safety without needing a garbage collector.

Zero-Cost Abstractions

High-level features compile down to efficient machine code with no runtime overhead.

Concurrency

Write concurrent code without data races, guaranteed at compile time.

Modern Tooling

Cargo package manager, built-in testing, and excellent documentation.

Your First Rust Program

Let's start with the traditional "Hello, World!" program. This is the simplest Rust program you can write:

Breaking it down:

  • fn main() - Defines the main function, the entry point of every Rust program
  • println! - A macro (note the !) that prints text to the console
  • {} - Curly braces define the function body

Running Your Program

To run a Rust program, you'll need to:

  1. Install Rust from rustup.rs
  2. Create a new file called main.rs
  3. Compile and run with: rustc main.rs && ./main

What's Next?

Now that you've written your first Rust program, you're ready to dive deeper into the language. In the next lesson, we'll explore variables, mutability, and data types in Rust.