summaryrefslogtreecommitdiff
path: root/structs/src/main.rs
blob: cf93866dc1126ab99a78e656f94115e4048eff52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#[derive(Debug)]
struct Rectangle {
    width: u32,
    height: u32,
}

impl Rectangle {

    fn area(&self) -> u32 {
        self.width * self.height
    }

    fn can_hold(&self, other: &Rectangle ) -> bool {
        self.width > other.width && self.height > other.height
    }

}

fn main() {
    let rect1 = Rectangle {
        width: 30,
        height: 50,
    };
    let rect2 = Rectangle {
        width: 3,
        height: 5,
    };
    println!("{:#?}", rect1);
    println!("The area of the rectangle is {} square pixels.", rect1.area());
    println!("{}", rect1.can_hold(&rect2));
}