On this page

What is Rust? Installation and first program

12 min read TextCh. 1 — Rust Fundamentals

What is Rust?

Rust is a systems programming language designed to provide performance comparable to C/C++ without sacrificing memory safety. It was originally created by Mozilla Research in 2010, and since 2021 it has been governed by the Rust Foundation, a nonprofit organization backed by companies including Microsoft, Google, Amazon, Meta, and Huawei.

Rust's value proposition is unique in the programming language ecosystem:

  • Memory safety without a garbage collector (GC): Rust guarantees at compile time that there will be no segmentation faults, dangling pointers, buffer overflows, or data races — all without a GC that could pause execution.
  • System-level performance: Rust code compiles to highly optimized native binaries. No virtual machine, no GC, no runtime overhead.
  • Fearless concurrency: Rust's type system makes concurrency errors impossible to compile. Rust calls this "fearless concurrency."
  • Zero-cost abstractions: High-level abstractions (iterators, closures, generic traits) have no runtime cost — they compile to the same code you would write by hand.

Why learn Rust in 2026

Rust has been the most loved language in the Stack Overflow annual survey for over nine consecutive years. But beyond the emotional factor, there are concrete reasons:

  1. The Linux kernel has accepted Rust code since version 6.1. There are already drivers written in Rust in the official kernel.
  2. Android uses Rust for new OS components, reducing memory-safety vulnerabilities by 70%.
  3. Windows incorporates Rust components in the kernel since 2023.
  4. WebAssembly: Rust is the primary language for compiling high-performance WASM.
  5. Salaries: Rust developers command significantly above-average salaries across multiple surveys.

Installation with rustup

rustup is the official Rust installer. It manages multiple compiler versions and associated tools.

On Linux and macOS:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

On Windows: Download rustup-init.exe from rustup.rs and run it.

After installation, restart your terminal and verify:

rustc --version   # rustc 1.94.0 (...)
cargo --version   # cargo 1.94.0 (...)
rustup --version  # rustup 1.27.x

The ecosystem tools

Installing Rust with rustup gives you:

Tool Purpose
rustc The Rust compiler
cargo Package manager and build tool
rustfmt Official code formatter
clippy Linter with advanced suggestions
rust-analyzer Language Server Protocol for IDEs

Cargo: the project manager

Cargo is the central tool of the Rust ecosystem. Unlike languages where the compiler and package manager are separate tools, Cargo unifies everything:

# Create a new binary project
cargo new my-project

# Create a library
cargo new my-library --lib

# Compile the project
cargo build

# Compile and run in development mode
cargo run

# Compile in release mode (optimized)
cargo build --release

# Run tests
cargo test

# Check code without compiling (faster)
cargo check

# Format code
cargo fmt

# Advanced linting
cargo clippy

Cargo project structure

my-project/
├── Cargo.toml      # Project manifest (dependencies, metadata)
├── Cargo.lock      # Exact dependency versions (for binaries)
└── src/
    └── main.rs     # Program entry point

For a library, the main file is src/lib.rs instead of src/main.rs.

Your first program

Rust has a special macro for printing: println!. The ! at the end indicates it's a macro, not a function. Macros in Rust can accept a variable number of arguments, which is impossible with regular functions without overloading.

fn main() {
    println!("Hello, world!");
    
    // Formatting with curly braces
    let x = 42;
    println!("The value is: {}", x);
    
    // Since Rust 1.58: direct variable capture
    println!("The value is: {x}");
    
    // Debug formatting with {:?}
    let tuple = (1, 2, 3);
    println!("{:?}", tuple);
    
    // Pretty-print with {:#?}
    println!("{:#?}", tuple);
}

Rust's philosophy: explicit safety

One of the most important differences from other languages is that Rust makes potentially failing operations explicit. Instead of exceptions that propagate silently, Rust uses types like Result<T, E> and Option<T> to represent success/failure and presence/absence of values.

This philosophy can be summarized as: if it compiles, it probably works correctly.

The Rust compiler (rustc) has error messages famous for being extremely clear and helpful. When your code doesn't compile, the compiler not only tells you what's wrong but frequently suggests how to fix it with messages like: "help: consider adding mut here."

History and evolution

  • 2006: Graydon Hoare starts Rust as a personal project
  • 2010: Mozilla adopts the project
  • 2015: Rust 1.0 — first stable release
  • 2021: Rust Foundation formally incorporated
  • 2022: Rust enters the Linux kernel
  • 2024: Rust in the Windows kernel
  • 2026: Rust 1.94 — the language continues growing with stability

Rust has a six-week release cycle: a new stable version every six weeks, guaranteeing backward compatibility with existing code.

Setting up the editor

For an optimal development experience:

# Install rust-analyzer (Language Server)
rustup component add rust-analyzer

# Install the formatter
rustup component add rustfmt

# Install clippy
rustup component add clippy

In VS Code, install the "rust-analyzer" extension (ms-rust-lang.rust-analyzer). In IntelliJ/RustRover (JetBrains), Rust integration is first-class.

Compiling and running directly

Although Cargo is the recommended tool, you can also compile individual files with rustc:

rustc main.rs
./main       # Linux/macOS
main.exe     # Windows

In real projects you will always use Cargo, but it's useful to know rustc to understand what's happening underneath.


In the next lesson we will explore variables and mutability — one of the first concepts where Rust differs radically from other languages.

rustup manages your toolchain
Use rustup update to update Rust to the latest stable version. With rustup toolchain install nightly you can install the nightly version to experiment with features in development.
Rust requires a C linker
On Windows install Visual Studio Build Tools or use WSL2. On Linux install gcc with your package manager. On macOS install Xcode Command Line Tools with xcode-select --install.
// src/main.rs — your first Rust program
fn main() {
    println!("Hello, world from Rust 1.94!");

    // Rust infers types automatically
    let name = "Rustacean";
    let version: u32 = 94;

    println!("Hello, {}! We use Rust 1.{}", name, version);

    // Variables are immutable by default
    // name = "other"; // Error: cannot reassign
}