RBE custom types structs activity 2

cat-town
Dan Buch 3 years ago
parent c57baae2cc
commit 90f6fdad97
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -24,6 +24,13 @@ fn rect_area(r: Rectangle) -> f32 {
(r.top_left.x - r.bottom_right.x) * (r.top_left.y - r.bottom_right.y)
}
fn square(p: &Point, d: f32) -> Rectangle {
Rectangle {
top_left: Point { x: p.x + d, y: p.y },
bottom_right: Point { x: p.x, y: p.y + d },
}
}
fn main() {
let name = String::from("Peter");
let age = 27;
@ -64,4 +71,9 @@ fn main() {
println!("rect in {:?}", rect);
println!("area of rect is {}", rect_area(rect));
let lower_left = Point { x: 4.1, y: 11.3 };
let d = 7.7f32;
let sq = square(&lower_left, d);
println!("sq from point={:?} of d={} is {:?}", lower_left, d, sq);
}

Loading…
Cancel
Save