Home New Trending Search
About Privacy Terms
#
#RustFormatting
Posts tagged #RustFormatting on Bluesky
struct Person { name: String, age: u32 }  impl std::fmt::Display for Person {     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {         write!(f, "{} ({} years old)", self.name, self.age)     } }  fn main() {     let person = Person { name: "Alice".to_string(), age: 30 };     println!("{}", person);     // Output: Alice (30 years old) }

struct Person { name: String, age: u32 } impl std::fmt::Display for Person { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{} ({} years old)", self.name, self.age) } } fn main() { let person = Person { name: "Alice".to_string(), age: 30 }; println!("{}", person); // Output: Alice (30 years old) }

🔍 #Rustlang Tip: Use the std::fmt::Display trait to customize how your structs are printed!

#RustFormatting #Rust30by30 #Day18

0 0 0 0