Introduction to Rust

1/14/2025

Introduction to Rust

Rust is a systems programming language focused on safety, speed, and concurrency.

Why Rust?

  • Memory safety: No null pointers or data races
  • Zero-cost abstractions: High-level features with no runtime overhead
  • Fearless concurrency: Safe parallel programming
  • Great tooling: Cargo, rustfmt, clippy

Installation

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

# Verify installation
rustc --version
cargo --version

Hello World

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

Cargo Basics

bash
# Create new project
cargo new my_project
cd my_project

# Build project
cargo build

# Run project
cargo run

# Run tests
cargo test

Variables

rust
fn main() {
    let x = 5;           // Immutable
    let mut y = 10;      // Mutable
    y = 15;
    
    const MAX: u32 = 100_000;  // Constant
}