27 lines
536 B
Rust
27 lines
536 B
Rust
// Procedural macro
|
|
// Derive macro
|
|
|
|
// #[derive(Debug)]
|
|
struct User {
|
|
first_name: String,
|
|
last_name: String,
|
|
email: String,
|
|
}
|
|
|
|
impl std::fmt::Display for User {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{} {}", self.first_name, self.last_name)
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let tim = User {
|
|
first_name: "Tim".into(),
|
|
last_name: "Huizinga".into(),
|
|
email: "tim@huizinga.dev".into(),
|
|
};
|
|
|
|
println!("User: {tim}");
|
|
// println!("User: {tim:?}");
|
|
}
|