You are on page 1of 1

#[derive(Debug)]

struct Rectangle {
   width: u32,
   length: u32,
}

impl Rectangle {
   fn area(&self) -> u32 {
       self.length * self.width
  }

   fn can_hold(&self, other: &Rectangle) -> bool {


       self.width > other.width && self.length > other.length
  }

   fn square(side: u32) -> Rectangle {


       Rectangle { width: side, length: side, }
  }
}

pub fn demo5() {

   let rect = Rectangle {


       width: 30,
       length: 50,
  };

   let rect1 = Rectangle {


       width: 3,
       length: 5,
  };

   let squ = Rectangle::square(10);

   println!("{:#?}", rect);
   println!("{}", rect.area());
   println!("{}", rect.can_hold(&rect1));
   println!("{}", rect.can_hold(&squ));

You might also like