← Back to archive

Stdle #166 · classes · 2026-11-19

What does this Rust snippet output?

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

trait Shape {
fn area(&self) -> f64;
fn describe(&self) -> String {
format!("area={}", self.area())
}
}
struct Sq(f64);
impl Shape for Sq {
fn area(&self) -> f64 { self.0 * self.0 }
}
fn main() {
let s: Box<dyn Shape> = Box::new(Sq(3.0));
println!("{}", s.describe());
}
Classes
4 attempts left

Answer & explanation