🦀

Rust Advanced

Ownership & borrowing, structs/enums, and Option/Result error handling.

3 lessons 5 tasks ⚡ Live compiler
Lessons Compiler Quiz Certificate

📚 Lessons

1 Ownership & borrowing

Each value has one owner; when it goes out of scope it is dropped. Borrowing (&) lends access without transferring ownership — the borrow checker prevents data races at compile time.

fn main() {
  let s = String::from("hi");
  let len = calc(&s);   // borrow
  println!("{} {}", s, len);
}
fn calc(x: &String) -> usize { x.len() }

2 Structs & enums

struct groups related fields; enum models a value that is one of several variants — perfect with match.

enum Shape { Circle(f64), Square(f64) }
fn area(s: &Shape) -> f64 {
  match s {
    Shape::Circle(r) => 3.14159 * r * r,
    Shape::Square(a) => a * a,
  }
}

3 Option, Result & safety

Rust has no null. Option<T> models maybe-absent values; Result<T, E> models success or error — forcing you to handle both. (The runnable example sums a range.)

fn main() {
    let mut sum = 0;
    for i in 1..=50 {
        sum += i;
    }
    println!("sum 1..=50 = {}", sum);
}

⚡ Rust Compiler

Code runs on a learning-oriented simulated runtime that supports common constructs (output, variables, arithmetic, conditionals and loops).

RUST

            

📝 Tasks

5 tasks across 2 pages — multiple-choice and fill-in (type the answer). Score 70% or higher to earn your certificate.

🎓 Certificate of Completion

🔒 Pass the quiz above (70%+) to unlock your downloadable certificate.