Implementing Debug Trait for Structs
In Rust, the Debug trait allows you to format your types using the {:?} formatter, making it easier to inspect and debug your code. Instead of manually implementing the Debug trait for every struct, Rust provides the convenient #[derive(Debug)] attribute to automatically generate a Debug implementation.
For this challenge, you will work with structs that represent different types of data. Your task is to implement the Debug trait using the derive macro and demonstrate its functionality with sample structs.
Your Task
- Define several structs representing various entities (e.g.,
Person,Point,Rectangle). - Derive the
Debugtrait for each struct using#[derive(Debug)].
Requirements
- Use the
#[derive(Debug)]attribute for all structs. - Define at least three structs, each with different fields and types.
No run yet
Press
Run to execute your code and see test results here.