Skip to content

Rust 101 — Fundamentals

You already know TypeScript. You understand types, functions, and how to build real software. This module uses that knowledge as a bridge — every concept is introduced by comparing it to something you already know, then showing the Rust way.

This module covers the core building blocks of Rust that map to everyday TypeScript patterns:

  • Variableslet, let mut, const, shadowing, and type inference
  • Functions — typed parameters, return types, and expression-oriented syntax
  • Control flowif as an expression, match, loop, while, for
  • Structs — the Rust alternative to classes and interfaces
  • Enums — algebraic data types and exhaustive pattern matching
  • CollectionsVec, HashMap, arrays, tuples, slices
  • Option and Result — replacing null/undefined and try/catch
  • Modules and crates — the Rust equivalent of ESM and npm

By the end you will have the vocabulary to read and write real Rust programs.

Both programs greet the user. The structure is similar, but Rust is compiled, statically typed, and has no runtime — println! is a macro that resolves format strings at compile time.

TypeScript
const name = "TypeScript developer";
console.log(`Hello, ${name}! Welcome to Rust.`);
Rust
fn main() {
let name = "TypeScript developer";
println!("Hello, {}! Welcome to Rust.", name);
}

Run the Rust snippet above directly in your browser.

fn main() {
let name = "TypeScript developer";
println!("Hello, {}! Welcome to Rust.", name);
}
In Rust, what is println! ?
What is the entry point of every Rust binary program?