Third exercise
Analyze and fix the following code by using the copy trait:
use std::fmt::Display; struct Point { c: char, x: i32, y: i32, } impl Display for Point { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}({},{})", self.c, self.x, self.y) } } fn main() { let p1 = Point { c: 'A', x: 1, y: 1 }; let p2 = p1; println!("{}", p1); println!("{}", p2); }
Hint
Implement the copy trait to add #[derive(Clone, Copy)] to the Point struct.