RBE custom types structs activity 2
This commit is contained in:
parent
c57baae2cc
commit
90f6fdad97
@ -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)
|
(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() {
|
fn main() {
|
||||||
let name = String::from("Peter");
|
let name = String::from("Peter");
|
||||||
let age = 27;
|
let age = 27;
|
||||||
@ -64,4 +71,9 @@ fn main() {
|
|||||||
|
|
||||||
println!("rect in {:?}", rect);
|
println!("rect in {:?}", rect);
|
||||||
println!("area of rect is {}", rect_area(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…
x
Reference in New Issue
Block a user