main.rs
 1  #[derive(Debug)]
 2  struct Rectangle {
 3      width: u32,
 4      height: u32,
 5  }
 6  
 7  impl Rectangle {
 8      fn area(&self) -> u32 {
 9          self.width * self.height
10      }
11      fn width(&self) -> bool {
12          self.width > 0
13      }
14  }
15  
16  fn main() {
17      let rect1 = Rectangle {
18          width: 30,
19          height: 50,
20      };
21  
22      println!(
23          "The area of the rectangle is {} square pixels.",
24          rect1.area()
25          );
26  
27      if rect1.width() {
28          println!("The rectangle has a nonzero width; it is {}", rect1.width);
29      }
30  }