← Back to archive

Stdle #74 · classes · 2026-08-19

What does this Rust snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

trait Doubler {
fn val(&self) -> i32;
fn doubled(&self) -> i32 { self.val() * 2 }
}
struct N(i32);
impl Doubler for N {
fn val(&self) -> i32 { self.0 }
}
fn apply(d: &dyn Doubler) -> i32 {
d.doubled()
}
fn main() {
println!("{}", apply(&N(21)));
}
Classes
4 attempts left

Answer & explanation