Getting Started

Rust Introduction

Discover Rust — the systems language that gives you memory safety without a garbage collector.

What is Rust?

Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It achieves memory safety without a garbage collector through its ownership system.

Rust has been voted "most loved programming language" in Stack Overflow surveys for 8+ consecutive years.

Why Rust?

  • Memory safety: No null pointers, no dangling references, no data races
  • No garbage collector: Manual-level performance, no GC pauses
  • Zero-cost abstractions: High-level features with no runtime overhead
  • Fearless concurrency: Ownership system prevents data races at compile time
  • Modern tooling: Cargo (build tool + package manager), excellent error messages

Getting Started

bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustc --version
cargo new hello-rust
cd hello-rust
cargo run

Example

rust
// src/main.rs
fn main() {
    // Variables are immutable by default
    let name = "Rust";
    let mut count = 0;  // mut makes it mutable

    count += 1;
    println!("Hello from {}! Count: {}", name, count);

    // Shadowing - create new binding with same name
    let x = 5;
    let x = x + 1;  // shadows previous x
    let x = x * 2;
    println!("x = {}", x);  // 12

    // Data types
    let integer: i32 = 42;
    let float: f64 = 3.14;
    let boolean: bool = true;
    let character: char = 'R';
    let tuple: (i32, f64, bool) = (500, 6.4, true);
    let array: [i32; 5] = [1, 2, 3, 4, 5];

    println!("{} {} {} {}", integer, float, boolean, character);
    println!("tuple.0 = {}", tuple.0);
    println!("array[2] = {}", array[2]);
}
Try it yourself — RUST