Impl `rect_area` for 3.1

cat-town
Dan Buch 8 years ago
parent e7e2d2749c
commit af11c29d9c
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

@ -2,17 +2,26 @@ struct Nil;
struct Pair(i32, f32);
#[derive(Debug)]
struct Point {
x: f32,
y: f32,
}
#[allow(dead_code)]
#[derive(Debug)]
struct Rectangle {
p1: Point,
p2: Point,
}
fn rect_area(rect: Rectangle) -> f32 {
let Rectangle {
p1: Point { x: x1, y: y1 },
p2: Point { x: x2, y: y2 }
} = rect;
((x1 - x2) * (y1 - y2)).abs()
}
fn main() {
let point: Point = Point { x: 0.3, y: 0.4 };
@ -34,4 +43,7 @@ fn main() {
let Pair(integer, decimal) = pair;
println!("pair contains {:?} and {:?}", integer, decimal);
println!("rect is {:?}", _rectangle);
println!("rect area is {}", rect_area(_rectangle));
}

Loading…
Cancel
Save