Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Algo parecido a una clase en Rust
- * Calculo del area de un rectangulo
- */
- #[warn(dead_code)]
- //#[derive(Debug)]
- struct Rectangle {
- x:u32,
- y:u32,
- }
- impl Rectangle{
- fn new (x:u32,y:u32)->Self {
- Self{x,y}
- }
- fn area(&self)->u32{
- self.x*self.y
- }
- fn get_x(&self)->u32{
- self.x
- }
- fn get_y(&self)->u32 {
- self.y
- }
- }
- fn main (){
- let rectangle = Rectangle::new(2,5);
- println! ("x :{}",rectangle.get_x());
- println! ("y :{}",rectangle.get_y());
- println! ("{}",rectangle.area());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement