Impl rect_area
for 3.1
This commit is contained in:
parent
e7e2d2749c
commit
af11c29d9c
@ -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…
Reference in New Issue
Block a user