Santa glared at the terminal, baffled. “A simple println!
! That’s all I needed! Why won’t it work?!” He tugged his beard, fuming. The elves had been cranking out code under his “motivational” leadership, but now even Santa’s Rust “expertise” was falling short.
Bernard, the Lead Elf, leaned over Santa’s shoulder, squinting at the code. “Wait… are those gifts for elves and reindeer too? Are you planning to give everyone presents this year?”
Santa slammed the laptop shut, his cheeks reddening. “It’s supposed to be a surprise! If Prancer finds out, she’ll livestream the announcement before the code even works. Now fix this, Bernard—discreetly.”
Bernard crossed his arms, smirking. “Santa, that’s ambitious. But this code is spaghetti. I’ll fix it—but you owe the elves an extra cocoa break.”
Santa growled. “Fine! Just fix it! And not a word to anyone until it’s done.”
Bernard chuckled, cracking his knuckles. “You got it, boss!”
If Bernard solves this problem, it will be likely that the elves and reindeer get gifts from Santa too, it'll be their lucky year, you just need to write a function so that Santa easily can log the gifts, the function should be able to take in either KidsGift
, ElvesGift
or ReindeerGift
and print them out.
Make sure you update the signature of the display_gift
function to accept any of the types.
If you're stuck or need a starting point, here are some hints to help you along the way!
Display
trait using use std::fmt::Display
.Display
trait.fn my_fn<T: fmt::Display>(arg: T) {
println!("{}", arg);
}
use std::fmt::Display;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;use std::fmt;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}pub fn display_gift(gift: &impl Display) { println!("{}", gift);}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: &impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Kids gift: {}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Elves gift: {}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Reindeer gift: {}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Gift for Kid {}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Gift for Elf {}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Gift for Reindeer {}", self.name) }}pub fn display_gift<T>(gift: T)where T: Display{ println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "KidsGift for {}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "ElvesGift for {}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "ReindeerGift for {}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub fn display_gift<T: fmt::Display> (gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: &impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt (&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Kids gift: {}", self.name) } }impl fmt::Display for ElvesGift { fn fmt (&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Elves gift: {}", self.name) } }impl fmt::Display for ReindeerGift { fn fmt (&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Reinder gift: {}", self.name) } }pub enum GitfType { KidsGift, ElvesGift, ReindeerGift,}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}//pub fn display_gift<T: Display>(gift: T) {// println!("{}", gift);//}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;#[derive(Debug)]pub struct KidsGift { pub name: String,}impl Display for KidsGift{ fn fmt(&self, f:&mut std::fmt::Formatter) -> Result<(), std::fmt::Error>{ write!(f,"{}",self.name) }}#[derive(Debug)]pub struct ElvesGift { pub name: String,}impl Display for ElvesGift{ fn fmt(&self, f:&mut std::fmt::Formatter) -> Result<(), std::fmt::Error>{ write!(f,"{}",self.name) }}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift{ fn fmt(&self, f:&mut std::fmt::Formatter) -> Result<(), std::fmt::Error>{ write!(f,"{}",self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;#[derive(Debug)]pub struct KidsGift { pub name: String,}impl Display for KidsGift{ fn fmt(&self, f:&mut std::fmt::Formatter) -> Result<(), std::fmt::Error>{ write!(f,"{}",self.name) }}#[derive(Debug)]pub struct ElvesGift { pub name: String,}impl Display for ElvesGift{ fn fmt(&self, f:&mut std::fmt::Formatter) -> Result<(), std::fmt::Error>{ write!(f,"{}",self.name) }}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift{ fn fmt(&self, f:&mut std::fmt::Formatter) -> Result<(), std::fmt::Error>{ write!(f,"{}",self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;#[derive(Debug)]pub struct KidsGift { pub name: String,}#[derive(Debug)]pub struct ElvesGift { pub name: String,}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: std::fmt::Display + std::fmt::Debug>(gift: T) { println!("{:#?}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display};use std::fmt;#[derive(Debug)]pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}#[derive(Debug)]pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display};use std::fmt;#[derive(Debug)]pub struct KidsGift { pub name: String,}#[derive(Debug)]pub struct ElvesGift { pub name: String,}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display, Formatter};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub fn display_gift(gift: &dyn Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl std::fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}pub struct Gift <'a> { pub name: &'a String,}impl <'a> From<&'a KidsGift> for Gift <'a> { fn from (i: &'a KidsGift) -> Self { Self { name: &i.name } }}impl <'a> From<&'a ElvesGift> for Gift <'a> { fn from (i: &'a ElvesGift) -> Self { Self { name: &i.name } }}impl <'a> From<&'a ReindeerGift> for Gift <'a> { fn from (i: &'a ReindeerGift) -> Self { Self { name: &i.name } }}impl <'a> std::fmt::Display for Gift <'a> { fn fmt (&self, b: &mut std::fmt::Formatter <'_>) -> std::fmt::Result { write!(b, "{}", self.name) }}impl std::fmt::Display for KidsGift { fn fmt (&self, b: &mut std::fmt::Formatter <'_>) -> std::fmt::Result { write!(b, "{}", self.name) }}impl std::fmt::Display for ElvesGift { fn fmt (&self, b: &mut std::fmt::Formatter <'_>) -> std::fmt::Result { write!(b, "{}", self.name) }}impl std::fmt::Display for ReindeerGift { fn fmt (&self, b: &mut std::fmt::Formatter <'_>) -> std::fmt::Result { write!(b, "{}", self.name) }}pub fn display_gift <'a> (gift: impl Into<Gift<'a>>) { let gift = gift.into(); println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
// use std::fmt::{Display, Result, Error, Formatter};use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{self, Display};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{self, Display};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{self, Display};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", &self.name) }}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", &self.name) }}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", &self.name) }}pub fn display_gift<T: std::fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display, Formatter};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: &T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;use std::fmt::Formatter;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;use std::fmt::Formatter;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display, Formatter};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", format!("{}", self.name)) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}// impl<'a> Into<&'a str> for &'a KidsGift {// fn into(self) -> &'a str {// &self.name// }// }// impl<'a> Into<&'a str> for &'a ElvesGift {// fn into(self) -> &'a str {// &self.name// }// }// impl<'a> Into<&'a str> for &'a ReindeerGift {// fn into(self) -> &'a str {// &self.name// }// }impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self.name) }}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self.name) }}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self.name) }}pub fn display_gift(gift: impl std::fmt::Display) { // let name: &str = gift.into(); println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: std::fmt::Display>(gift: &T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: std::fmt::Display>(gift: &T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { writeln!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { writeln!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { writeln!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.name) }}pub fn display_gift(gift: impl fmt::Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;#[derive(Debug)]pub struct KidsGift { pub name: String,}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}#[derive(Debug)]pub struct ElvesGift { pub name: String,}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}#[derive(Debug)]pub struct ReindeerGift { pub name: String,}impl fmt::Display for ReindeerGift { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}pub struct ElvesGift { pub name: String,}pub struct ReindeerGift { pub name: String,}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}impl fmt::Display for KidsGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ElvesGift { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}impl fmt::Display for ReindeerGift { fn fmt(&self, f:&mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.name) }}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display, Formatter, Result};pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.write_str(&self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt;pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: fmt::Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::{Display};pub struct KidsGift { pub name: String,}impl std::fmt::Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl std::fmt::Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl std::fmt::Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift<T: Display>(gift: T) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}
use std::fmt::Display;pub struct KidsGift { pub name: String,}impl Display for KidsGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ElvesGift { pub name: String,}impl Display for ElvesGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub struct ReindeerGift { pub name: String,}impl Display for ReindeerGift { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }}pub fn display_gift(gift: impl Display) { println!("{}", gift);}pub fn main() { let kids_gift = KidsGift { name: "toy car".to_string(), }; let elves_gift = ElvesGift { name: "vertical monitor".to_string(), }; let reindeer_gift = ReindeerGift { name: "carrot".to_string(), }; display_gift(&kids_gift); display_gift(&elves_gift); display_gift(&reindeer_gift);}