Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Square {
- length: i32,
- }
- impl Square {
- fn new(length: i32) -> Square {
- Square { length }
- }
- fn area(&self) -> i32 {
- self.length * self.length
- }
- }
- struct Rectangle {
- width: i32,
- height: i32,
- }
- impl Rectangle {
- fn new(width: i32, height: i32) -> Rectangle {
- Rectangle { width, height}
- }
- fn area(&self) -> i32 {
- self.width * self.height
- }
- }
- fn main() {
- let rect = Rectangle::new(30, 50);
- let sqr = Square::new(30);
- println!("The area of rectangle is {}.", rect.area());
- println!("The area of square is {}.", sqr.area());
- }
Add Comment
Please, Sign In to add comment