How to Use std

:fmt for Custom Formatting

Implement the Display trait to define custom string formatting for your Rust types.

Implement the std::fmt::Display trait for your type to define custom formatting for end users.

use std::fmt;

struct User {
    username: String,
}

impl fmt::Display for User {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "User: {}", self.username)
    }
}

fn main() {
    let user = User { username: "alice".to_string() };
    println!("{user}");
}