Impl & Methods

struct Rectangle {

    width: u32,

    height: u32,
}


impl Rectangle {

    // Syntatic sugar for fn area(self: Self) -> u32 {

    fn area(self) -> u32 {

        self.width * self.height
    }
}

fn main() {

    let rect = Rectangle {

        width: 2,

        height: 3,
    };
    
    assert_eq!(6, rect.area());
}