Skip to content

Overview

6 min read

Welcome to Rust! This section will get you up and running with your first Rust program.



By the end of this section, you will:

  • Understand why Rust is valuable for TS/JS developers
  • Have Rust installed and configured on your system
  • Write and run your first Rust program
  • Understand Cargo and its role (think: npm + webpack + more)
  • Know how to use the online Rust Playground

  • Reading: 45-60 minutes
  • Installation & Setup: 15-30 minutes
  • Hands-on Practice: 30-45 minutes
  • Total: 1.5-2 hours

If you want to jump right in:

  1. Install Rust (15 minutes)
  2. Hello World (15 minutes)
  3. Cargo Basics (15 minutes)

Then come back and read the other topics at your leisure.


1. Why Rust (understand the motivation)
2. Installation (get Rust on your machine)
3. Hello World (write your first program)
4. Cargo Basics (learn the tooling)
5. Playground (for quick experiments)
1. Playground (try Rust immediately, no install)
2. Installation (once you're convinced)
3. Hello World
4. Why Rust (understand what you just did)
5. Cargo Basics

Compare Rust to what you already know:

TypeScript/Node.js:

  • Interpreted/JIT compiled
  • Garbage collected
  • Single-threaded event loop
  • Runtime errors
  • 50-100ms startup time
  • 50-200 MB memory baseline

Rust:

  • Compiled to native code
  • No garbage collection
  • Safe, compiler-checked, opt-in multithreading (fearless concurrency)
  • Compile-time error checking
  • <1ms startup time
  • 1-5 MB memory baseline

You’ll learn:

  • How to install Rust using rustup
  • How to verify your installation
  • How to update Rust
  • Editor setup for the best experience

Your first Rust program:

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

Compared to TypeScript, where top-level code runs directly with no required entry-point function:

console.log("Hello, world!");

Cargo is like npm, webpack, and more combined:

FeatureTypeScript/JSRust
Package Managernpm/yarn/pnpmCargo
Build Toolwebpack/viteCargo
Test Runnerjest/vitestCargo
Formatterprettierrustfmt
Lintereslintclippy
Documentationtypedocrustdoc
Benchmarking(various)Cargo bench
Task Runnernpm scriptsCargo

All in one tool!

play.rust-lang.org lets you:

  • Try Rust without installing anything
  • Share code snippets
  • Test ideas quickly
  • Learn with instant feedback

TypeScript/JavaScript:

Terminal window
node app.js # V8 parses, then JIT-compiles hot code at runtime
ts-node app.ts # Strips types, then runs through the same V8 pipeline

Rust:

Terminal window
rustc main.rs # Compiled to native binary
./main # Execute native code

Impact:

  • Faster execution, especially CPU-bound work (no GC pauses)
  • Smaller deployments (single binary)
  • No runtime dependencies
  • Slower build times (seconds vs milliseconds)

TypeScript/JavaScript:

  • Automatic memory management
  • GC pauses (unpredictable timing)
  • Memory overhead
  • Easy to use

Rust:

  • Ownership system (compile-time memory management)
  • No GC pauses (predictable performance)
  • Minimal memory overhead
  • Learning curve

TypeScript:

let x: any = "hello"; // Escape hatch — type checking is disabled
x = 42; // No complaint from the compiler
let y = x.length; // No error: silently `undefined` at runtime

Rust:

let x = "hello"; // Type inference
let y = x.len(); // Always safe, or won't compile

TypeScript:

function divide(a: number, b: number): number {
if (b === 0) {
throw new Error("Division by zero"); // Exception
}
return a / b;
}

Rust:

fn divide(a: i32, b: i32) -> Result<i32, String> {
if b == 0 {
Err("Division by zero".to_string()) // Explicit error value
} else {
Ok(a / b)
}
}

No exceptions in Rust! All errors are explicit in the type system.


  • Install Rust on your machine
  • Run cargo --version successfully
  • Create and run a “Hello World” program
  • Understand what Cargo does
  • Configure your editor with rust-analyzer
  • Experiment with the Rust Playground
  • Create a custom Cargo project
  • Read Cargo.toml and understand its structure

rustup - The Rust toolchain installer (like nvm for Node.js)

cargo - Build tool and package manager (like npm + webpack)

rustc - The Rust compiler. Where tsc erases types and emits JavaScript that still needs a runtime, rustc produces a self-contained native binary.

crates - Rust packages (like npm packages)

Cargo.toml - Project manifest (like package.json)

main.rs - Entry point file (like index.ts)

Don’t worry if these don’t make sense yet - they will soon!


Problem: Installation didn’t add rustup to PATH

Solution:

Terminal window
# Restart your terminal first.
# On macOS/Linux you can also source the env file in the current shell:
source "$HOME/.cargo/env"

Note: source ~/.cargo/env is a Unix shell command and does not work in Windows PowerShell or cmd.exe. On Windows, the rustup installer adds Cargo to your PATH automatically; just open a new terminal window.

Problem: Same as above

Solution: Restart your terminal (Windows), or source the cargo env file in the current shell (macOS/Linux)

Problem: Missing C compiler (Rust needs it for linking)

Solution:

  • macOS: xcode-select --install
  • Linux: sudo apt install build-essential
  • Windows: Install Visual Studio Build Tools

Problem: First compile is always slow

Why: Rust compiles dependencies from source

Tips:

  • Use cargo build without --release during development
  • Dependencies are cached after first build
  • Consider using sccache for faster recompilation


Let’s get Rust installed and write your first program!

Or jump straight to: