quest

Sign in to start training

quest keeps your progress, streaks, and scores tied to your account — so you can pick up on any device.

Synced everywhere. Progress follows you across laptop and phone.
Streaks & stats. See your daily run and every score over time.
Your profile. A name and avatar for the work you do here.

We only use Google to sign you in and sync progress. No posting, no contacts — ever.

Core Beginner

06  Structs & enums

Give a Rect a constructor and an area method, then compute the area of an enum that holds different data per variant.

Step 1 / 2

Give Rect a new constructor and an area method.

Hints
  • Methods live in impl Rect { fn area(&self) -> u32 { ... } }.
  • Self inside an impl block means the type itself.
06_structs_enums.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
struct Rect { w: u32, h: u32 }

impl Rect {
    fn new(w: u32, h: u32) -> Self {
        Rect { w, h }
    }
    fn area(&self) -> u32 {
        self.w * self.h
    }
}