Rust provides a special kind of struct known as a tuple struct. Unlike a regular struct with named fields, a tuple struct groups fields together without names, making it useful for lightweight structures where naming each field isn't necessary.
A tuple struct looks like this:
struct Point(i32, i32, i32);
You can create an instance of a tuple struct just like you would with a tuple and access its fields using dot notation.
Your task is to define a tuple struct called Rectangle
with two fields:
f32
.f32
.Then, implement a function area
that calculates and returns the area of the rectangle by multiplying its width and height.
pub struct Point(pub i32, pub i32, pub i32);
Here's how your code will be tested:
let rect = Rectangle(4.0, 5.0);
assert_eq!(area(&rect), 20.0);
let square = Rectangle(10.0, 10.0);
assert_eq!(area(&square), 100.0);
If you get stuck, consider these hints:
rect.0
for width and rect.1
for height).