From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Challenge: Represent shapes

Challenge: Represent shapes - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Challenge: Represent shapes

- [Narrator] It's time for a challenge to practice using structs. Your goal for this challenge is to define a struct named Rectangle to represent, well, a rectangle. It should store two fields for the width and height of the rectangle. Both stored as 64 bit floating point values. In addition to those fields, your struct also needs to implement a couple of methods and a function. The first method named, get area, should return a 64 bit float representing the rectangles area. Which can be calculated by multiplying its width by its height. The other method named, Scale, should take a 64 bit float value as input. And then scale both dimensions of the rectangle by that value individually multiplying the width and height by the scaler. Finally, your rectangle struct should have an associated function named, New, to create a new rectangle. It should accept two input arguments for width and height and then return a new…

Contents