Skip to content

Commit e8140db

Browse files
committed
derive Debug trait and use dbg!()
1 parent 92dff5b commit e8140db

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

c5_struct/src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#[derive(Debug)]
22
struct Rectangle {
33
width: u32,
44
height: u32,
@@ -42,9 +42,10 @@ fn main() {
4242
"The area of the rectangle is {} square pixels.",
4343
rect1.area()
4444
);
45+
let scale=2;
4546

4647
let rect1 = Rectangle {
47-
width: 30,
48+
width: dbg!(30*scale),
4849
height: 50,
4950
};
5051
let rect2 = Rectangle {
@@ -55,7 +56,9 @@ fn main() {
5556
width: 60,
5657
height: 45,
5758
};
58-
59+
// dbg!() takes ownership of an expression. We use & instead.
60+
dbg!(&rect1);
61+
dbg!(&rect3);
5962
println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2));
6063
println!("Can rect1 hold rect3? {}", rect1.can_hold(&rect3));
6164

0 commit comments

Comments
 (0)