How to implement Display trait

Implement the Display trait by defining a fmt method that uses write! to format your struct's fields into a string.

Implement the std::fmt::Display trait for your type by defining an impl block and providing a fmt method that writes to the formatter.

use std::fmt;

struct Point {
    x: i32,
    y: i32,
}

impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "({}, {})", self.x, self.y)
    }
}

Use {} in format strings to print instances of your type.