Skip to content
binshelf/ rust

Search lessons

Type a Rust, TypeScript or C# term, like Option, null or E0382.

    Compare Rust with

    Rust for TypeScript & C# developers

    Learn Rust with the language you already know.

    Every lesson puts your language next to the Rust that does the same job, then explains what changes: who owns memory, what the compiler checks, and why. Every example on this site is compiled and run before it's published.

    Which language do you know best?

    Every example compares Rust with the one you pick. Change it any time with the switch at the top of the page.

    Side by side

    No null in Rust: a value that might be missing is an Option, and the compiler makes you handle both cases.

    TypeScript
    users.ts
    function findUser(id: number): string | undefined {
      return id === 1 ? "Ada" : undefined;
    }
    
    const user = findUser(2);
    console.log(user ?? "nobody");
    C#
    Users.cs
    var user = FindUser(2);
    Console.WriteLine(user ?? "nobody");
    
    static string? FindUser(int id) => id == 1 ? "Ada" : null;
    Rust
    fn find_user(id: u32) -> Option<&'static str> {
        if id == 1 { Some("Ada") } else { None }
    }
    
    fn main() {
        let user = find_user(2);
        println!("{}", user.unwrap_or("nobody"));
    }

    Output

    nobody

    How each lesson works

    1. Concept map

      A table of each idea in your language and in Rust, to scan before reading.

    2. Side-by-side code

      The same small program in your language and in Rust, with the same names.

    3. Which one to use

      What each option is, when to use it, why, and how.

    4. Under the hood

      Memory diagrams and real compiler errors, explained.

    5. Common pitfalls

      The traps TypeScript and C# developers hit first.

    6. Try it

      Port a short program to Rust, with a hint and a checked solution.

    Curriculum

    1. Module 0 Orientation & tooling

      Why Rust works without a garbage collector, and the tools you'll use every day: rustup, Cargo, clippy and rustfmt.

      1. 0.1Why Rust, and the mental model shift
      2. 0.2Tooling, Cargo & project layout

    2. Module 1 Fundamentals

      Variables, mutability, shadowing, number types and functions, why almost everything in Rust is an expression, and what Rust's punctuation means.

      1. 1.1Variables, mutability & shadowing
      2. 1.2Primitive & compound types
      3. 1.3Functions, expressions & statements
      4. 1.4Reading Rust's symbols: &, *, ', ::, ! and ?

    3. Module 2 Ownership & memory

      Where values live, who frees them, and why assigning a String moves it instead of sharing it.

      1. 2.1Stack vs. heap
      2. 2.2Ownership and move semantics
      3. 2.3Copy vs. Clone

    4. Module 3 Borrowing & slices

      Lending values without giving them away: shared and mutable references, zero-copy slices, and how to choose what a function takes.

      1. 3.1References: &T and &mut T
      2. 3.2Slices: &str and &[T]
      3. 3.3Choosing parameter types: T, &T, &mut T or Box<T>

    5. Module 4 Control flow & pattern matching

      if and loop as expressions, exhaustive match, and the short forms: if let, while let and let-else.

      1. 4.1Loops & conditional expressions
      2. 4.2Exhaustive match & destructuring
      3. 4.3if let, while let & let-else

    6. Module 5 Structs, methods & enums

      Data and behavior without classes or inheritance, and enums that carry data.

      1. 5.1Structs & impl blocks
      2. 5.2Enums with data

    7. Module 6 Nullability & error handling

      Option instead of null, Result instead of exceptions, and the ? operator.

      1. 6.1Option instead of null
      2. 6.2Result and the ? operator
      3. 6.3Panics, custom errors, thiserror & anyhow

    8. Module 7 Modules & crates

      Organizing code with modules and visibility, and projects with crates, workspaces and features.

      1. 7.1Modules, visibility & paths
      2. 7.2Crates, workspaces & features

    9. Module 8 Collections & strings

      Vec, HashMap and friends, and why Rust strings are UTF-8 and can't be indexed by position.

      1. 8.1Vec, HashMap, HashSet & BTreeMap
      2. 8.2Strings: UTF-8 vs UTF-16

    10. Module 9 Traits & generics

      Rust's answer to interfaces, generic bounds, static vs. dynamic dispatch, and the standard traits.

      1. 9.1Traits
      2. 9.2Generics, bounds & where
      3. 9.3impl Trait vs. dyn Trait
      4. 9.4Standard traits

    11. Module 10 Closures & iterators

      Closures and what they capture, and lazy iterator chains that compile to plain loops.

      1. 10.1Closures & Fn, FnMut, FnOnce
      2. 10.2Lazy iterators

    12. Module 11 Lifetimes & smart pointers

      How long references are valid, deterministic cleanup with Drop, and shared ownership when you need it.

      1. 11.1Lifetimes
      2. 11.2Drop & smart pointers
      3. 11.3Shared ownership & interior mutability

    13. Module 12 Concurrency & async

      Threads and channels, compile-time thread safety with Send and Sync, and async Rust with Tokio.

      1. 12.1Threads, channels & shared state
      2. 12.2Send & Sync
      3. 12.3Async, futures & Tokio

    14. Module 13 Testing, macros & unsafe

      Built-in tests and doc tests, macros and serde, what unsafe Rust is for, and running Rust in the browser with WebAssembly.

      1. 13.1Tests & doc tests
      2. 13.2Macros & serde
      3. 13.3unsafe & FFI
      4. 13.4Rust & WebAssembly