We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6031064 commit c9165d4Copy full SHA for c9165d4
rustlang_book/structs/src/main.rs
@@ -1,4 +1,33 @@
1
+#[derive(Debug)]
2
+struct Rectangle {
3
+ width: u32,
4
+ height: u32,
5
+}
6
+
7
+impl Rectangle {
8
+ fn area(&self) -> u32 {
9
+ return self.height * self.width;
10
+ }
11
12
+ fn can_hold(&self, rectangle: &Rectangle) -> bool {
13
+ return self.height > rectangle.height && self.width > rectangle.width;
14
15
16
17
fn main() {
- println!("Hello, world!");
18
+ let rect1 = Rectangle {
19
+ width: 30,
20
+ height: 50,
21
+ };
22
+ let rect2 = Rectangle {
23
+ width: 10,
24
+ height: 40,
25
26
+ let rect3 = Rectangle {
27
+ width: 60,
28
+ height: 45,
29
30
31
+ println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2));
32
+ println!("Can rect1 hold rect3? {}", rect1.can_hold(&rect3));
33
}
0 commit comments