Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- println!("The area of rectangle is {}.", rect.area());
- }
Add Comment
Please, Sign In to add comment