Introduction
In this lab, we learn about the #[derive]
attribute in Rust, which allows the compiler to provide basic implementations for certain traits such as Eq
, PartialEq
, Ord
, PartialOrd
, Clone
, Copy
, Hash
, Default
, and Debug
. These traits can also be manually implemented if a more complex behavior is needed. The lab provides example code showcasing the usage of these traits on different tuple structs such as Centimeters
, Inches
, and Seconds
.
Note: If the lab does not specify a file name, you can use any file name you want. For example, you can use
main.rs
, compile and run it withrustc main.rs && ./main
.