main.rs
1 #[derive(Debug)] 2 struct Rectangle { 3 width: u32, 4 height: u32, 5 } 6 7 impl Rectangle { 8 fn square(size: u32) -> Self { 9 Self { 10 width: size, 11 height: size, 12 } 13 } 14 } 15 16 fn main() { 17 let sq = Rectangle::square(3); 18 println!("{:#?}", sq); 19 }