Struct method woop
This commit is contained in:
parent
d64444550a
commit
1622e4bcea
@ -4,20 +4,20 @@ struct Rectangle {
|
|||||||
height: u32,
|
height: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Rectangle {
|
||||||
|
fn area(&self) -> u32 {
|
||||||
|
self.width * self.height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rect1 = Rectangle {
|
let rect1 = Rectangle {
|
||||||
width: 30,
|
width: 30,
|
||||||
height: 50,
|
height: 50,
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("rect1 is {:#?}", rect1);
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"The area of the rectangle is {} square pixels.",
|
"The area of the rectangle is {} square pixels.",
|
||||||
area(&rect1)
|
rect1.area()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn area(rectangle: &Rectangle) -> u32 {
|
|
||||||
rectangle.width * rectangle.height
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user