Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Display Trait

Create a Color struct with fields r, g, b (all u8). Implement the Display trait so it prints in the format rgb(R, G, B). Print a color with values 255, 128, 0.

Expected output:

text
Color: rgb(255, 128, 0)

Hints:

  • Add use std::fmt; at the top
  • Implement impl fmt::Display for Color
  • Use write!(f, "rgb({}, {}, {})", self.r, self.g, self.b)
rust
fn main() {
}