Challenge 2: Adding a Constructor — Possible Solution ==================================================================== struct Circle { radius: f64, } impl Circle { fn new(radius: f64) -> Circle { Circle { radius } } fn area(&self) -> f64 { 3.14159 * self.radius * self.radius } } fn main() { let c = Circle::new(4.0); println!("Area: {}", c.area()); } WHY THIS WORKS AS AN ANSWER ------------------------------ fn new(radius: f64) -> Circle has NO self parameter, which is exactly what makes it an ASSOCIATED FUNCTION rather than a method — it can't be called on an existing instance (there isn't one yet, which is the whole point of a constructor), only via Circle::new(...), using the :: namespacing syntax this chapter introduced. Inside new, Circle { radius } uses Rust's field-init shorthand — since the parameter is already named radius, matching the struct's own field name, it doesn't need to be written as radius: radius. Circle::new(4.0) replaces the earlier struct-literal syntax (Circle { radius: 4.0 }) with a proper constructor call — functionally equivalent here, but the associated-function form becomes valuable once a constructor needs to do more than a plain literal could (validation, computing a derived field, etc.), which is exactly why Rust code almost always reaches for a ::new() constructor by convention, mirroring the exact pattern String::from(...) already demonstrated back in Chapter 1.