$ cd ../ (all courses)

Rust

Memory safety without garbage collection. Fast and fearless.

⚠ pattern-based checks (code is analyzed, not compiled)

About Rust

Rust is a systems language focused on safety and performance. Its ownership model catches memory bugs at compile time — no GC, no segfaults. Used in Firefox, Discord, Cloudflare, and the Linux kernel. NOTE: Code is checked by pattern matching, not compiled. Focus on idiomatic Rust.

Quick-reference cheat sheet
// Rust cheat-sheet

fn main() {
    let x = 42;             // immutable by default
    let mut y = 10;         // mut to make mutable
    y += 1;

    let name: &str = "ada"; // string slice
    let owned: String = String::from("ada");

    println!("Hello, {}!", name);
    println!("x = {}, y = {}", x, y);

    // Conditions are expressions
    let kind = if x > 0 { "positive" } else { "non-positive" };

    // Loops
    for i in 0..5 { println!("{}", i); }

    let nums = vec![1, 2, 3, 4];
    let sum: i32 = nums.iter().sum();

    // Option / Result
    let maybe: Option<i32> = Some(5);
    match maybe {
        Some(n) => println!("got {}", n),
        None => println!("nothing"),
    }
}

fn add(a: i32, b: i32) -> i32 {
    a + b           // no semicolon = return
}

struct Point { x: i32, y: i32 }
impl Point {
    fn new(x: i32, y: i32) -> Self { Point { x, y } }
}

// Traits
trait Greet { fn hello(&self) -> String; }

// Closures
let add1 = |x: i32| x + 1;

// Error handling with Result
fn parse_int(s: &str) -> Result<i32, std::num::ParseIntError> {
    s.parse::<i32>()
}

Tasks

  1. 01
    Hello, World!
    println!("Hello, World!");
    intro
  2. 02
    let and mut
    Declare an immutable and a mutable variable.
    intro
  3. 03
    Primitive types
    Annotate i32, f64, bool.
    intro
  4. 04
    &str vs String
    Declare a slice and an owned String.
    intro
  5. 05
    Function with return
    Write fn add(a: i32, b: i32) -> i32.
    easy
  6. 06
    if as an expression
    Assign from if/else.
    easy
  7. 07
    For loop with range
    Print 1..=10 using a range.
    easy
  8. 08
    loop with break
    Use loop and break.
    easy
  9. 09
    Tuples
    Destructure a tuple.
    easy
  10. 10
    Fixed-size arrays
    Declare and index a [i32; 5].
    easy
  11. 11
    Sum a Vec
    Sum a vec! of i32 using iter().sum().
    medium
  12. 12
    Vec push and len
    Build a Vec dynamically.
    medium
  13. 13
    match expression
    Match on an i32 to print a label.
    medium
  14. 14
    Option<T>
    Use Some / None and unwrap_or.
    medium
  15. 15
    Result<T, E>
    Pattern-match a Result.
    medium
  16. 16
    Borrow a String
    Pass &String to a function.
    medium
  17. 17
    Mutable reference
    Modify a Vec through &mut.
    medium
  18. 18
    Define a struct
    Struct Point and an impl block.
    hard
  19. 19
    Define an enum
    Enum with multiple variants.
    medium
  20. 20
    Iterator: map + collect
    Square each element of a Vec<i32>.
    hard
  21. 21
    Iterator: filter
    Keep only even numbers.
    hard
  22. 22
    Trait + impl
    Define trait Greet with fn hello(&self).
    hard
  23. 23
    Generic function
    fn largest<T: PartialOrd>(list: &[T]) -> &T
    hard
  24. 24
    Closures
    Define and call a closure.
    hard
  25. 25
    String slice
    Take a slice of a String.
    hard
  26. 26
    HashMap
    Use std::collections::HashMap.
    hard
  27. 27
    Lifetimes
    Annotate lifetimes on a function.
    hard
  28. 28
    Box for recursion
    Recursive enum with Box.
    hard
  29. 29
    ? operator
    Propagate errors with ?.
    hard
  30. 30
    #[derive(Debug)]
    Derive Debug to print a struct.
    medium
  31. 31
    Variable shadowing
    Shadow a variable changing its type.
    easy
  32. 32
    Tuple destructuring
    Destructure a tuple into bindings.
    easy
  33. 33
    Iterate an array
    Loop with for over an array.
    easy
  34. 34
    While loop countdown
    Countdown using while.
    easy
  35. 35
    loop returns value
    Return a value from loop via break.
    medium
  36. 36
    Build a String
    Use push_str and push.
    easy
  37. 37
    String slice
    Take a &str slice from a String.
    medium
  38. 38
    Mutable borrow
    Pass &mut String to a function.
    medium
  39. 39
    impl method
    Add a method to a struct.
    medium
  40. 40
    Associated function
    Constructor-like associated fn.
    medium
  41. 41
    Enum with data
    Define an enum with variants holding data.
    medium
  42. 42
    if let pattern
    Use if let on Option.
    medium
  43. 43
    Iterator sum
    Sum a Vec with iterators.
    medium
  44. 44
    map + collect
    Square numbers via iterator chain.
    medium
  45. 45
    Filter even numbers
    Keep evens with .filter.
    medium
  46. 46
    Define a trait
    Trait with default implementation.
    hard
  47. 47
    Generic function
    Find largest with PartialOrd bound.
    hard
  48. 48
    Closure
    Closure capturing environment.
    medium
  49. 49
    Match on Result
    Handle Result with match.
    medium
  50. 50
    fold accumulator
    Sum via fold.
    hard
  51. 51
    Rc<T> shared ownership
    Share ownership with Rc::clone.
    hard
  52. 52
    RefCell interior mutability
    Mutate through RefCell<T>.
    hard
  53. 53
    Spawn a thread
    Spawn and join a thread.
    hard
  54. 54
    Channels (mpsc)
    Send a message through a channel.
    hard
  55. 55
    Mutex<T>
    Lock a Mutex and mutate.
    hard
  56. 56
    Trait object dyn
    Vec of trait objects.
    hard
  57. 57
    zip + enumerate
    Combine iterator adapters.
    hard
  58. 58
    From for custom error
    impl From<ParseIntError> for MyError.
    hard
  59. 59
    async fn + .await
    Define an async function and await it.
    hard
  60. 60
    no_std crate
    Mark a crate as no_std for bare metal.
    medium
  61. 61
    panic_handler for bare metal
    Define a #[panic_handler] that loops forever.
    medium
  62. 62
    #[no_mangle] entry point
    Expose a _start symbol with C ABI.
    medium
  63. 63
    VGA buffer raw write
    Write a byte to the 0xb8000 VGA text buffer.
    hard
  64. 64
    Volatile write to MMIO
    Use core::ptr::write_volatile for memory-mapped I/O.
    hard
  65. 65
    #[repr(C)] for FFI layout
    Stable struct layout for C interop.
    medium
  66. 66
    extern "C" function declaration
    Call a C library function (abs).
    medium
  67. 67
    Manual bitflag helpers
    Set and test bits with | and &.
    medium
  68. 68
    Newtype pattern for safety
    Wrap u32 in struct UserId(u32).
    medium
  69. 69
    PhantomData marker
    Carry an unused type parameter with PhantomData.
    hard
  70. 70
    Dereference a raw pointer
    Read through *const i32 inside unsafe.
    hard
  71. 71
    static mut + unsafe access
    Increment a static mut COUNTER.
    hard
  72. 72
    AtomicUsize counter
    Lock-free counter with AtomicUsize.
    hard
  73. 73
    Arc<Mutex<T>> across threads
    Share mutable state safely between threads.
    hard
  74. 74
    mpsc channel send/recv
    Pass values between threads with std::sync::mpsc.
    hard
  75. 75
    Custom Drop impl (RAII)
    Run code when a value goes out of scope.
    medium
  76. 76
    Send + Sync trait bound
    Require a generic type to be thread-safe.
    hard
  77. 77
    wasm-bindgen exported fn
    Expose a Rust fn to JavaScript.
    medium
  78. 78
    Import a JS function into wasm
    Declare extern "C" { fn log(s: &str); } via wasm-bindgen.
    hard
  79. 79
    crate-type = cdylib
    Configure Cargo.toml for a wasm cdylib.
    easy
  80. 80
    Plain wasm export (no bindgen)
    Export add(a,b) directly with #[no_mangle] extern "C".
    medium
  81. 81
    Capstone — Freestanding kernel skeleton
    Combine no_std, panic_handler, _start, and a VGA write.
    hard