← All Exercises

Rust Struct Basics

basicrust~15min

Background

Structs group related data in Rust, with methods defined in impl blocks and traits providing behavior.

Problem

Create a Rectangle struct with width and height, implement an area method, and derive Debug and PartialEq traits.

Input

Width and height as f64 values.

Output

A Rectangle with area method and Debug/PartialEq support.

Sample tests

Sample 1

Input: Rectangle{width:5.0, height:3.0}
Expected: area=15.0

Your solution

Learning objective

Learn struct definition, impl blocks, method syntax, and derive macros for common traits.